pefi Posted yesterday at 08:29 AM Posted yesterday at 08:29 AM I need to modify a few block definitions per drawing by adding 2 new attributes. Fixed location, they wont be visible, so I do not care if they are overlapping with other content or not. I use them as a "meta data" storage. Now, what's the best way to do it? I'm considering reinserting the block (prepared separately, with required modifications) or editing the block definition in place. The number of drawings and blocks is too large for manual modifications. I'm OK with LISP as well, but I will be populating the data from excel, so VBA seems to be the natural choice. Any advice if there is abetter way of doing it? Any opinions, comments, are more than welcome. I'm at the "brain storm" stage P.S. I currently open the block editor, paste the 2 attributes, close block editor, attsync, done. Maybe recreating that process in a scripted way with LISP would be easier? Quote
SLW210 Posted yesterday at 10:38 AM Posted yesterday at 10:38 AM Probably the same either way. LISP/Script would be quite capable, lot's of code around for adding attributes, pretty sure Lee Mac has something. VBA, IMO, might have a slight advantage running on multiple drawings. .NET or Python an option? 1 Quote
pefi Posted yesterday at 11:52 AM Author Posted yesterday at 11:52 AM (edited) Thanks! I'm OK to do it drawing by drawing. I can script handling the batch. I think in python , so definitely yes. .NET - never used it. I just found out the expresstools command blockreplace, but I'm struggling to convince it to use external file as the new block. I might dig into Lee Mac library... I prepared the new block as external file, but I'm not asked to redefine the block even when inserting with full file path. Possibly some system variable controls that (*). Edit: * https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-15A13868-7582-4CCD-A8FC-9AF2D05E689C BLOCKREDEFINEMODE Edited yesterday at 11:54 AM by pefi add link Quote
pefi Posted yesterday at 12:09 PM Author Posted yesterday at 12:09 PM (edited) Looks like a lot can be done with -bedit, -insert, -bsave, -bclose, attsync . I just need to put it together, bur I think I have a solution. 1. Prepare external drawing with attributes for adding 2. Open the drawing that needs to be modified (easily scripted for batch work) Script: (defun c:add_to_block_from_file ( / ) ;Add attribues or anything else from external file to a block definition (setq block_name "BLOCK_NAME") (setq att_file_path "C:\\PATH_TO_THE_FILE_FOR_ADDING.dwg") ;Use \\ in the path! (command "-bedit" block_name) (command "insert" att_file_path "E" "Y" "0,0" "1" "1" "0") (command "bsave") (command "bclose" "") (command "attsync" "Name" block_name) ) at this moment the blocks contain the new attributes so the drawing can be modified or saved. Edited yesterday at 12:59 PM by pefi Quote
BIGAL Posted 18 hours ago Posted 18 hours ago You mention reading from Excel, its not a problem you can read cells from CAD, so if you have multiple blocks can be done. It would be simple to add to your defun say two columns in Excel Blocknames & dwgname with path. Need a sample Excel. 1 Quote
pefi Posted 9 hours ago Author Posted 9 hours ago Thank you very much! I'm not sure if I understand you, you mean reading excel directly using AutoLISP? I never tried to do anything with excel and LISP together. When I have data in excel I use VBA and calling LISP scripts from VBA. The sample data set attached - there are 4 columns, file, bhd_ins - block handle that needs to get the "data injection", bhd_type and bhd_line - are the names of attributes in that block. The block handles in the sample set correspond to the real handles on the sample drawing. The content of bhd_type and bhd_line is made up, but that won't make a difference. sample_drawing.dwg handle_table.xlsx Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.