I've developed a couple of lisp routines that look for specific block names and edits those blocks. However, at least half the blocks we use are dynamic, so we end up with a lot of *U... blocks which the routines don't recognize as the same block.
Is there a way to automatically rename blocks back to their original name without losing their dynamic properties? If at all possible, I'd this to be done without having to enter in any information (i.e. block names), select blocks, match blocks to their names, etc.
Thanks for your help.
Solved! Go to Solution.
Solved by Shneuph. Go to Solution.
Dynamic blocks will always have the anonymous name once they are changed in any way. What you need to do is get the effective name using vlisp. The effective name is the same as the original block name. Here is a simple example to get the effective name of one block.
(vl-load-com)
(setq enb (entsel))
(vlax-get-property (vlax-ename->vla-object (car enb)) "effectivename")
I'm a little lost on how to incorporate this vlisp into my code. I'm not at all familiar with how to use vlisp in my programming. Could you help me apply it to the following routine?
(if
(setq BLKSS (ssget "X" '((2 . "NCS_Grid - Dynamic"))))
(foreach BLK (mapcar 'cadr (ssnamex BLKSS))
(setq
BLKDATA (entget BLK)
BLKSCL (rtos (cdr (assoc 41 BLKDATA)) 2 0)
LAYNAME (strcat "A-Anno-Grid-Iden-" BLKSCL)
) ;end setq
(command
"-layer" "new" LAYNAME "color" "94" LAYNAME "ltype" "Phantom2" LAYNAME ""
"chprop" BLK "" "layer" LAYNAME ""
) ;end command
) ;end foreach
) ;end if
What are you trying to accomplish with the Dynamic Blocks ?
Regards.
Tharwat
I don't understand how your question relates. We use our dynamic blocks for all sorts of things: doors with stretchable sizes, room and ceiling tags with togglable leaders, millwork elevations with visibility settings for drawers/shelves, etc.
My question is , what are you expecting from a routine to do ?
Thanks
The code I posted above is part of a routine that places blocks on specific layers based on the block name and insertion scale. I have another routine that changes the grid location attribute of our view titles (again requiring the block name) based on the drawing name, the name of the titleblock insert, and its location on the sheet.
Check this out Buddy ...
(defun Move-Dyn-Block-To-layer (Blkname LayerName / ss)
; Tharwat 17. 06. 2011
(vl-load-com) (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 (strcat Blkname ",`*U*"))) ) ) ((lambda (i / sset e) (while (setq sset (ssname ss (setq i (1+ i)))) (if (eq Blkname (vla-get-EffectiveName (vlax-ename->vla-object sset)) ) (entupd (cdr (assoc -1 (entmod (subst (cons 8 LayerName) (assoc 8 (setq e (entget sset))) e ) ) ) ) ) ) ) ) -1 ) (princ) ) )
And you can call the sub-routine with the following code to change the layer that a specific Dynamic Block lays on to another .
(Move-Dyn-Block-To-layer "Blkname" "LayerName")
Tharwat
@Anonymous wrote:I'm a little lost on how to incorporate this vlisp into my code. I'm not at all familiar with how to use vlisp in my programming. Could you help me apply it to the following routine?
(if
(setq BLKSS (ssget "X" '((2 . "NCS_Grid - Dynamic"))))
(foreach BLK (mapcar 'cadr (ssnamex BLKSS))
(setq
BLKDATA (entget BLK)
BLKSCL (rtos (cdr (assoc 41 BLKDATA)) 2 0)
LAYNAME (strcat "A-Anno-Grid-Iden-" BLKSCL)
) ;end setq
(command
"-layer" "new" LAYNAME "color" "94" LAYNAME "ltype" "Phantom2" LAYNAME ""
"chprop" BLK "" "layer" LAYNAME ""
) ;end command
) ;end foreach
) ;end if
I don't think it is going to work the way you are going about it with the selection set filter. You'll have to step through each block checking the effective name and then change the block to the new layer. Maybe something like this will work better for you?...
(vl-load-com) (if (setq BLKSS (ssget "X" '((0 . "Insert")))) (foreach BLK (mapcar 'cadr (ssnamex BLKSS)) (setq vl-block (vlax-ename->vla-object blk) BLKEffectivename (vla-get-effectivename vl-block) BLKDATA (entget BLK) BLKSCL (rtos (cdr (assoc 41 BLKDATA)) 2 0) LAYNAME (strcat "A-Anno-Grid-Iden-" BLKSCL) );end setq (if (= BLKEffectivename "NCS_Grid - Dynamic") (progn (command "-layer" "new" LAYNAME "color" "94" LAYNAME "ltype" "Phantom2" LAYNAME "" "chprop" BLK "" "layer" LAYNAME "" );end command
);progn
);end if
);end foreach
);end if
Thanks, Shneuph! That's exactly what I was looking for; I just didn't know how to incorporate the vlisp to target the intended block.