Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need lisp to change layer of all nested objects

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
ksmith84
2515 Views, 5 Replies

Need lisp to change layer of all nested objects

Howdy, I am looking for a lisp routine to add to search selected block/blocks to find any objects on layer "A-EquipLwr" and have them changed to layer "-PATT". Both layers are existing in the dwg, all the blocks have only 2 layers contained in them (A-EquipLwr and 0), but there are multiple variations of the block for different purposes. Does anyone have a lisp that will do this layer change in 1 step?  Thank you in advance.

 

Note: I want to keep the layer name as it is, since it is connected to other objects in the drawing which are not a part of blocks.


~¤~
^C^CMoonwalk
5 REPLIES 5
Message 2 of 6
Lee_Mac
in reply to: ksmith84

Try the following quickly written code:

 

(defun c:fixblocks ( / a b f i l s )
    (setq a "A-EQUIPLWR"
          b "-PATT"
    )
    (defun f ( n / e x )
        (if (and (not (member n l)) (setq e (tblobjname "block" n)))
            (progn
                (setq l (cons n l))
                (while (setq e (entnext e))
                    (if (= (strcase a) (strcase (cdr (assoc 8 (setq x (entget e))))))
                        (entmod (subst (cons 8 b) (assoc 8 x) x))
                    )
                    (if (= "INSERT" (cdr (assoc 0 x))) (f (cdr (assoc 2 x))))
                )
            )
        )
    )
    (if (setq s (ssget '((0 . "INSERT"))))
        (repeat (setq i (sslength s))
            (f (cdr (assoc 2 (entget (ssname s (setq i (1- i)))))))
        )
    )
    (command "_.regen")
    (princ)
)

 

Due to the recursive nature of the code, the above should also account for nested blocks, nested to any depth.

Message 3 of 6
ksmith84
in reply to: Lee_Mac

It works like a charm! Thank you once again Lee! It seems I've got more code studying to do haha.

~¤~
^C^CMoonwalk
Message 4 of 6
Lee_Mac
in reply to: ksmith84

Excellent to hear! - You're most welcome ksmith Smiley Happy

Message 5 of 6
XIJIANGWOO
in reply to: ksmith84

Hello All,

 

Would anyone know how to alter this lisp universally to select all and execute without user input ?  

 

I'm am trying to just open the drawing and have it run automatically. 

 

Thank you in advance , 

Message 6 of 6

On @Lee_Mac 's code, just replace this line:

(if (setq s (ssget '((0 . "INSERT"))))

With this other:

(if (setq s (ssget "_X" '((0 . "INSERT"))))

The "_X" forces ssget to select all, bypassing user input

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost