I have a simple script to select blocks by name and move them to a layer. What should be added to include in selection set also blocks that have been modified by a dynamic parameter (blocks that have been scaled, rotated etc from dynamic parameter grips).
(defun c:xx2yy ()
(prompt "\move blocks xx to layer "yy")(terpri)
(setq Blks (ssget "_x" '((0 . "insert")(2 . "xx"))))
(command "chprop" "p" "" "la" "yy" "")
(princ)
)
thanks!
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Robert
try
(defun c:xx2yy ( / BLKN BLKS HND I XXBLKS) (prompt "\nmove blocks xx to layer yy") (if (setq blks (ssget "_x" (list '(0 . "insert") (cons 2 "xx,`*U*")))) (progn (setq i 0 xxblks (ssadd) );; setq (while (setq hnd (ssname blks i)) (setq blkn (vla-get-effectivename (vlax-ename->vla-object hnd))) (if (wcmatch blkn "xx") (ssadd hnd xxblks) );; if (setq i (1+ i)) );; while (if xxblks (command "chprop" xxblks "" "la" "yy" "") );; if );; progn );; if (princ) );; xx2yy
HTH
Henrique
In addition to Henrique's excellent suggestion, the following code will be compatible with earlier versions of AutoCAD (in which there is no ActiveX effectivename property) and will also process blocks which reside in all layouts (not just the current space):
(defun c:xx2yy ( / e i s x ) (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "`*U*,xx")))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) x (entget e) ) (if (= "xx" (LM:blockname (vlax-ename->vla-object e))) (entmod (subst '(8 . "yy") (assoc 8 x) x)) ) ) ) (princ) ) ;; Block Name - Lee Mac ;; Returns the true (effective) name of a supplied block reference (defun LM:blockname ( obj ) (if (vlax-property-available-p obj 'effectivename) (defun LM:blockname ( obj ) (vla-get-effectivename obj)) (defun LM:blockname ( obj ) (vla-get-name obj)) ) (LM:blockname obj) ) (vl-load-com) (princ)
@Lee_Mac wrote:
...
the following code will be compatible with earlier versions of AutoCAD (in which there is no ActiveX effectivename property)
...
Nice thinking, Lee
@ robert06
You're welcome, Robert
Glad i could help
Henrique
@hmsilva wrote:
@Lee_Mac wrote:...
the following code will be compatible with earlier versions of AutoCAD (in which there is no ActiveX effectivename property)
...
Nice thinking, Lee
Thank you Henrique - enjoy your weekend!