Redefine a block using file

Redefine a block using file

NVIT
Enthusiast Enthusiast
1,261 Views
2 Replies
Message 1 of 3

Redefine a block using file

NVIT
Enthusiast
Enthusiast
Hi, NOOB here. I found this code from http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/update-blocks-amp-attributes-lisp/td-... But, that one redefines all block definitions. I'd like to change it to redefine a single block: In the active dwg, redefine an existing (existing), inserted block using a .dwg (file). The file has attribute tags used by the existing. The file may have been revised with added or deleted attribute tags. The existing has attributes and values. I'd like the existing to match the tags in the dwg. At the same time, existing values should be kept. I'd like to run it like: (Redefine "block1" "c:\\folder\\block1")
0 Likes
1,262 Views
2 Replies
Replies (2)
Message 2 of 3

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> In the active dwg, redefine an existing (existing), inserted block using a .dwg (file)

You can insert the dwg-file (using command _INSERT, select the new dwg) and if this dwg-file has the same name as the block-definition in your current drawing then AutoCAD asks you if you want to re-define it.

 

With Attributes you have to be careful. I would recommand to only re-define block-defintions that have the same attribute-tags as the existing block-defintion has.

If the naming is different or the new block has less attributes then the existing one the whole system is not stable. Values might be lost after _ATTSYNC _ATTEXT or _DATAEXTRACTION can then give invalid results, so be very careful with block-redefinition, when attribute-tags are different.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 3

Anonymous
Not applicable

Ok a one-off magic bullet:

 

(command "-insert" "X:/_Projects/CivStr/STAMPS_WORKING/STAMP "(command))
(command "attsync" "n" "STAMP")

The above inserts the block STAMP from the directory listed (note the forward slashes not backslashes or use double backslashes).  That will redefine the block and the following (command) cancels the insertion prior to placement. The second line ATTSYNCs the block.  Simply add this to a function and edit the block name and directory as needed.

(defun c:fixstamp ()
(command "-insert" "X:/_Projects/CivStr/STAMPS_WORKING/STAMP "(command))
(command "attsync" "n" "STAMP")
)

 

OR

 

add just the two lines (modified as needed) to a lisp function that is loaded at startup (appload startup suite, acaddoc.lsp, acad.lsp, etc.) and the block will be updated when you open it.

 

and as Alfred points out, take great care redefining blocks with attributes.  Make sure attribute tag names are the same and any new attributes have preset values.  As ALWAYS, NEVER duplicate tag names in the same block.

 

 

0 Likes