Jump to content

Block definition modification - adding 2 attributes.


Recommended Posts

Posted

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?

Posted

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?

  • Like 1
Posted (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 by pefi
add link
Posted (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 by pefi
Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...