PDA

View Full Version : All objects in various layers to only one layer


pt_zooropa
2008-06-19, 11:54 PM
Hi,
Is there any way possible, through a routine lisp, change all layers of a particular design for only one layer, for example, layer 0, including blocks, etc.?

Adesu
2008-06-20, 01:13 AM
Hi pt_zooropa
here a code to change all object to layer 0

(defun c:test (/ ss ssl cnt ssn)
(if
(setq ss (ssget "x"))
(progn
(setq ssl (sslength ss))
(setq cnt 0)
(repeat
ssl
(setq ssn (ssname ss cnt))
(command "_change" ssn "" "p" "la" "0" "")
(setq cnt (1+ cnt))
) ; repeat
) ; progn
) ; if
(princ)
) ; defun


Hi,
Is there any way possible, through a routine lisp, change all layers of a particular design for only one layer, for example, layer 0, including blocks, etc.?

pt_zooropa
2008-06-20, 01:42 AM
Hi pt_zooropa
here a code to change all object to layer 0

(defun c:test (/ ss ssl cnt ssn)
(if
(setq ss (ssget "x"))
(progn
(setq ssl (sslength ss))
(setq cnt 0)
(repeat
ssl
(setq ssn (ssname ss cnt))
(command "_change" ssn "" "p" "la" "0" "")
(setq cnt (1+ cnt))
) ; repeat
) ; progn
) ; if
(princ)
) ; defun

It works! But objects stay in original colors and i want to change them to be by layer

jmcshane
2008-06-20, 10:09 AM
Have you tried the "LAYMRG" command?

pt_zooropa
2008-06-20, 10:12 PM
Have you tried the "LAYMRG" command?
I want a routine...not a command...

Ed Jobe
2008-06-20, 10:19 PM
I want a routine...not a command...

A command is a routine.

'gile'
2008-06-21, 08:19 AM
Hi,

Something like this ?

(vl-load-com)
(vlax-for blk (vla-get-blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(vlax-for obj blk
(vla-put-Layer obj "0")
(vla-put-Color obj 256)
)
)

pt_zooropa
2008-06-21, 07:19 PM
Hi,

Something like this ?

(vl-load-com)
(vlax-for blk (vla-get-blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(vlax-for obj blk
(vla-put-Layer obj "0")
(vla-put-Color obj 256)
)
)

That´s it...but it stops with a nil...something is wrong.

'gile'
2008-06-21, 08:53 PM
That´s it...but it stops with a nil...something is wrong.

No it's OK, vlax-for returns the result of the last evaluation, and vla-put-Color always returns nil.

pt_zooropa
2008-06-22, 01:06 AM
This is better because all objects (including blocks) changes equal.
Ok. And if i want to put them (all objects) in a specific layer that doesn´t exist?

'gile'
2008-06-22, 11:06 AM
Hi,

Here's a routine, it requires a valid layer name as argument (string)

;;; AllObjectToLayer
;;; Changes all drawing objects (even blocks and nested blocks) to
;;; the specified layer and color "ByLayer"
;;; Creates the layer if it doesn't yet exists
;;;
;;; Argument
;;; LayerName : string (a valid layername according to EXTNAMES settings)
;;;
;;; Using : (AllObjectToLayer "MyLayer")

(defun AllObjectToLayer (LayerName / acdoc)
(setq acdoc (vla-get-activeDocument (vlax-get-acad-object)))
(if (snvalid LayerName)
(progn
(or (tblsearch "LAYER" LayerName)
(vla-add (vla-get-Layers acdoc) LayerName)
)
(vlax-for blk (vla-get-Blocks acdoc)
(vlax-for obj blk
(vla-put-Layer obj LayerName)
(vla-put-Color obj 256)
)
)
)
(princ "\nInvalid layer name")
)
)

pt_zooropa
2008-06-23, 04:18 PM
Hi,

Here's a routine, it requires a valid layer name as argument (string)

;;; AllObjectToLayer
;;; Changes all drawing objects (even blocks and nested blocks) to
;;; the specified layer and color "ByLayer"
;;; Creates the layer if it doesn't yet exists
;;;
;;; Argument
;;; LayerName : string (a valid layername according to EXTNAMES settings)
;;;
;;; Using : (AllObjectToLayer "MyLayer")

(defun AllObjectToLayer (LayerName / acdoc)
(setq acdoc (vla-get-activeDocument (vlax-get-acad-object)))
(if (snvalid LayerName)
(progn
(or (tblsearch "LAYER" LayerName)
(vla-add (vla-get-Layers acdoc) LayerName)
)
(vlax-for blk (vla-get-Blocks acdoc)
(vlax-for obj blk
(vla-put-Layer obj LayerName)
(vla-put-Color obj 256)
)
)
)
(princ "\nInvalid layer name")
)
)
Dont work. Try include in code the name of the layer - TFM

Opie
2008-06-23, 04:23 PM
Dont work. Try include in code the name of the layer - TFM
Your previous request was for a layer that did not exist. The routine 'gile' provided required an existing layer. For the routine to work correctly, you will need to create the desired layer and then run the routine.

'gile'
2008-06-23, 05:46 PM
Read the comment at the begining of the code.

Try (AllObjectToLayer "TFM") if "TFM" is the name of the layer.
If the layer doen't yet exists in the drawing it sould be created.

pt_zooropa
2008-06-23, 10:08 PM
Read the comment at the begining of the code.

Try (AllObjectToLayer "TFM") if "TFM" is the name of the layer.
If the layer doen't yet exists in the drawing it sould be created.
Thank you!