Hi,
NOOB here.
I found this code (attached) 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")
How 'bout something like this:
(command "insert" (strcat DwAg "=" DwgB)^c^c) where DwgA is the existing block in the drawing and DwgB is the path and name of the block that replaces the one in the dwg.
@NVIT wrote:
....
(Redefine "block1" "c:\\folder\\block1")
If you're going to have to spell out the Block name and drawing path/name each time you use such a routine, it won't save you much time and effort compared to just doing it directly:
-INSERT [with the hyphen so it doesn't use the dialog box];
BlockName=DrawingName
Yes to the question of whether to Redefine it;
<Esc> to cancel it without Inserting another;
ATTSYNC as needed....
If the DrawingName drawing is in a folder in the Support File Search Path list, you don't even need to include the path part for it.
If you're going to use -INSERT as someone else has suggested, it would redefine all insertions which is not what u want, I think. I understand u want to redefine only one of the insertion's tag & values so that way is not going to do what u need. One way is to get the updated attributes (added, erased or the same) from the external dwg and replace its values only on the block insertion you've selected. For this u can update only the new values that share the same tags (file & existing) on only one block insertion or even change the tag string but it would b difficult (if not impossible) to add new tags or erase the existing one as long as some synchronize command can revert any changes made, mostly on the erased ones. So I think a different approach should b considered to accomplish your goal. U can change tags string and/or values but not add attributes or erase them without affect the other insertions of the same block definition. I would suggest using Groups (not tested), or XRefs w constant Attrs (as long they are not copied) or unique block definitions (no copies) and still get tags&values from an external dwg file which u can read without open it. Remember that blocks references (the inserted ones) are just instances of block collections defined in the document database, your drawing.
I wish I were wrong to help u more.... and learn.
@NVIT wrote:
.... to redefine a single block:
....
I'd like to run it like:
(Redefine "block1" "c:\\folder\\block1")
So Post 4 raises the critical question: By "redefine a single block" in Post 1, do you mean a single Block definition, or a single Block insertion/reference? Post 4 assumes the latter, but the "run it like" thing above suggests the former to me, because "block1" as a text string could only be a Block name, not an inserted Block entity. A clarification would be in order.
@doglips wrote:
How 'bout something like this:
(command "insert" (strcat DwAg "=" DwgB)^c^c) ....
By the way, just so people know, in regard to the invalid-in-AutoLisp ^c^c in there, see this discussion.
I agree that for a single block, I see no programming required.
Use INSERT and ATTSYNC (if necessary).
An alternative is used (command) as ENTER.
While it is true tat (command) can fail in new versions and the alternative (command-s) does not work.
Example:
(setq FullPathBlk "c:\\folder\\block1.dwg") (setq NameBl "block1") (cond ((tblsearch "BLOCK" NameBl) (command "_.insert" (strcat NameBl "=" FullPathBlk)) (command) (prompt (strcat "\nRedefine block: [ " NameBl " ].")) ) (T (command "_.insert" FullPathBlk) (command) (prompt (strcat "\nDefined block reference: [ " NameBl " ].")) ) )
@joselggalan wrote:
....
While it is true tat (command) can fail in new versions ....
.... ((tblsearch "BLOCK" NameBl) (command "_.insert" (strcat NameBl "=" FullPathBlk)) (command) (prompt (strcat "\nRedefine block: [ " NameBl " ].")) ....
The (command) function is still fully functional in newer versions except within an *error* handler [and even there, you can make it work with some machinations]. Apart from there, I'm not aware of any failure issue.
Doesn't that redefinition need to include a "Yes" answer to the question of whether to redefine it?
@Kent1Cooper wrote:
The (command) function is still fully functional in newer versions except within an *error* handler [and even there, you can make it work with some machinations]. Apart from there, I'm not aware of any failure issue.
I try not to use "command" in my programs, but I use ..
I'm talking about (command) literal, not (command "._com .." "_xx"), and remember having problems "mapcar" and "lambda".
I have also used new features for managing errors using "COMMAND": * pop-Error-mode *, * push-bug-using-command *, * push-bug-using-stack *. (Only if strictly necessary)
@Kent1Cooper wrote:
Doesn't that redefinition need to include a "Yes" answer to the question of whether to redefine it?
apologies,
I use "(setvar 'expert 2)" before the code ...
Hi,
Here you have an approach to get on your proposed task avoiding the use of INSERT. It is a not a complete solution but it's something worth to try.
See notes on the attached file. I didn't know how to get the appropriate insertion point for new attributes so they come on top of the existing ones, maybe someone could help.
My two cents in the weekend.
I'm open to suggestion and corrections.
Justo Aguiar.
Can't find what you're looking for? Ask the community or share your knowledge.