layer name change lsp

layer name change lsp

nychoe1
Advocate Advocate
489 Views
3 Replies
Message 1 of 4

layer name change lsp

nychoe1
Advocate
Advocate

Thanks for making this Lisp, I'm using it well.

I would like to add one thing. When using this Lisp,  try to exclude the layer being frozen.

therefore

Except for objects whose layers are frozen, I want only non-frozen objects to run with this Lisp.

thanks for reading

some help... experts...

 

(defun c:lcc (/ SetLayer obj acdoc blocks)
(vl-load-com)
(defun SetLayer (blockName layerName)
(vlax-for obj (vla-Item blocks blockName)
(vla-put-Layer obj layerName)
(if (= (vla-get-ObjectName obj) "AcDbBlockReference")
(SetLayer (vla-get-Name obj) layerName)
)
)
)
(if (and (setq obj (car (entsel "\nmake layer name same")))
(setq obj (vlax-ename->vla-object obj))
(= (vla-get-ObjectName obj) "AcDbBlockReference")
)
(progn
(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
blocks (vla-get-Blocks acdoc)
)
(SetLayer (vla-get-Name obj) (vla-get-Layer obj))
(vla-Regen acdoc acActiveViewport)
)
)
(princ)
)

0 Likes
Accepted solutions (1)
490 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor
Accepted solution

try this:

; lcc changes all items on Thaw layers inside block to match with layer name block is currently placed on
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layer-name-change-lsp/m-p/11929749#M447473
(defun c:lcc (/ SetLayer obj acdoc blocks lays)
(vl-load-com)
(defun SetLayer (blockName layerName / lyr objlyr)
 (vlax-for obj (vla-Item blocks blockName)
  (setq lyr (vla-get-Layer obj)) ; get object's layer name
  (setq objlyr (vla-Item lays lyr)) ; get layer object
  (if (= ':vlax-false (vlax-get-property objlyr 'Freeze)) ; if not frozen
   (vla-put-Layer obj layerName)
  )
  (if (= (vla-get-ObjectName obj) "AcDbBlockReference")
   (SetLayer (vla-get-Name obj) layerName)
  )
 )
)
 (if 
  (and 
   (setq obj (car (entsel "\nMake Layer name the same")))
   (setq obj (vlax-ename->vla-object obj))
   (= (vla-get-ObjectName obj) "AcDbBlockReference")
  )
  (progn
   (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
     blocks (vla-get-Blocks acdoc)
     lays (vla-get-Layers acdoc) ; get layer table
   )
   (SetLayer (vla-get-Name obj) (vla-get-Layer obj))
   (vla-Regen acdoc acActiveViewport)
   (princ(strcat"\nAll Objects on Thawed Layers inside Selected Block [" (vla-get-Name obj) "] Changed to Layer Name [" (vla-get-Layer obj) "]"))
  ) ; progn
  (princ"\nObject Selected is Not a Block")
 ) ; if
 (princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 4

nychoe1
Advocate
Advocate

thank you... it's good working...

0 Likes
Message 4 of 4

paullimapa
Mentor
Mentor

glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes