Jump to content

Select objects to new Layer


jyan2000

Recommended Posts

Is there any lisp to move selected objects to new layer? I found this code (below) works well.. However inside blocks dont chage.

 

(defun c:nl ( / ss layer)

(and

(princ "\nSelect objects to change to new layer: ")

(setq ss (ssget))

(setq layer (getstring "\nNew layer name: "))

(or

(snvalid layer)

(prompt "\nInvalid layer name.")

)

(vl-cmdf "_.-layer" "_M" layer "")

(vl-cmdf "_.chprop" ss "" "_La" layer "")

(setvar "clayer" "0")

)

(princ)

)

Link to comment
Share on other sites

Hi jyan, welcome to cadtutor.net

 

I don't know if it exists, but I modified your provided routine to achieve the desired result

 

(defun c:nl (/ ss layer cnt en)
 (vl-load-com)
 (and
   (princ "\nSelect objects to change to new layer: ")
   (setq ss (ssget))
   (setq layer (getstring "\nNew layer name: "))
   (or
     (snvalid layer)
     (prompt "\nInvalid layer name.")
   )
   (vl-cmdf "_.-layer" "_M" layer "")
   (vl-cmdf "_.chprop" ss "" "_La" layer "")
   (setvar "clayer" "0")
 )
;part added by Jef! on june 05 2017
;inspired by Peter Jamtgaard FIXBLKS. Put into lambdas with Cwake's help.
 (setq cnt (sslength ss))
 (while (setq en (ssname ss (setq cnt (1- cnt))))
   (if (= "INSERT" (cdr (assoc 0 (entget en))))
     ((lambda (en / elst bnam flst)
        (setq elst (entget en)
              bnam (cdr (assoc 2 elst))
              flst nil
        )
        ((lambda (func)
           (func bnam)
         )
          (lambda (bnam / benam)
            (if (not (member bnam flst))
              (progn
                (setq flst  (cons bnam flst)
                      benam (tblobjname "block" bnam)
                )
                (while (setq benam (entnext benam))
                  (if (= (cdr (assoc 0 (entget benam))) "INSERT")
                    (func (cdr (assoc 2 (entget benam))))
                    (vla-put-layer
                      (vlax-ename->vla-object benam)
                      layer
                    )
                  )
                )
              )
            )
          )
        )
      )
       en
     )
   )
   (princ)
 )
)

 

Cheers!

Link to comment
Share on other sites

Hi Jef!

 

That's fantastic. I've been searching for this code for months. You r brilliant. Thank you very much.

 

Best Regards

Jyan

Link to comment
Share on other sites

Hi Jef!

 

That's fantastic. I've been searching for this code for months. You r brilliant. Thank you very much.

 

Best Regards

Jyan

 

I'M glad I could help you out. You are welcome... and don't forget the code tags, it makes Hulk go green :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...