i want to rename all the blocks in my drawings via the following
Lisp-Script by adding the Filename to the Blockname.
For me it looks correct but it dont work. Where is my fault ?
Thanks for every help
Bert Zorn
(setq Filename (strcase (substr (GETVAR "DWGNAME") (+ 1 (strlen (getvar
"DWGPREFIX"))))))
(setq blk (tblnext "BLOCK" T))
(while blk
(setq ct 0)
(setq blkname (cdr (assoc 2 blk)))
(setq newName (strcat Filename "_" blkname))
(setq blkElName (tblobjname "block" blkname))
(setq ss (entget blkElName))
(princ (strcat "\nNew Name = " newName))
(setq ss
(subst (cons 2 newName) ; new name
(assoc 2 ss) ; old Name
ss))
(print (entmod ss))
(setq blk (tblnext "BLOCK" nil))
)
Regards,
Steffen
On Wed, 03 Dec 1997 10:06:02 +0100, Bert Zorn <BZ...@compuserve.com>
wrote:
Logically it IS correct but leagally it's not.
The problem is that if Autocad allowed you to change the block name in
the block definition table, any INSERTs in the drawing's main entity
data would still have the old block name. This would cause an immediate
discrepancy in that inserts will exist within the drawing for which
there are no definitions (because you have changed their names) and
Autocad will not allow this.
It actually states in the Autolisp manual that although you can use
(entmod) to modify the entities within a block definition you cannot
modify the actual BLOCK entity itself. Which is why you get a 'nil'
returned from the (entmod) command.
One way round this would be to create new block definitions with the new
names by using (entmake) and copying the subentities etc from the block
table. Then search and replace the block names in the inserts in the
main entity section. Using (ssget "X") with a filter is the best way to
get all the inserts.
Finally you can then purge the old blocks after you have reloaded the
drawing.
Messy I know but thats the way it is. Autocad will not let you have
inserts in the drawing for which there are no block definitions.
Unfortunately, I don't have a ready made routine to do this as it's not
something I've needed to do. Maybe some else here has?
If you are still struggling post me a message and I'll see what I can
do.
Ian Gallaher.
By the way if you want to reply to me direct you will have to remove the
x from my e-mail address. Sorry but it helps to cut out the dross I get
sent by automated messaging systems.
Sorry guy's it's been a long day.
Slap my forehead why didn't I remember that.
Ignore that heap of rubbish I just sent.
I think I'll go home now.
Bye.
Hope this helps
Steve Fry