PDA

View Full Version : Change layer of block on locked layer in paper space



jpaulsen
2008-11-10, 06:33 PM
I work with LDT and LDT inserts a block named ACADD_ZZ in paper space to keep track of which project the drawing is associated with. Sometimes that block ends up on a locked layer which causes LDT to display errors.

My goal is to change the ADCADD_ZZ block to layer 0.

I just spent the last 1.5 hours reading the Help and forums and haven't gotten very far. I'm taking baby steps but this is what I have:

(defun c:test ()
; (setq ss1 (ssget "x" '((2 . "addcad_zz"))))
; (setq en (ssname ss1 0))
(setq en (entnext))
(setq ed (entget en)) ; Sets ed to the entity data for entity name en.
(setq ed
(subst (cons 8 "0")
(assoc 8 ed) ; Changes the layer group in ed.
ed ; to layer 0.
)
)
(entmod ed) ; Modifies entity en's layer in the drawing.
)
I got this directly from the help. It works but only on the first object in the drawing (entnext). I tried adding lines 2 and 3 and commenting line 4 but that doesn't work. I get the following error:
; error: bad argument type: lselsetp nil

How do I select the ADCADD_ZZ block and change it's layer?

Will it be possible to change the layer of the block while the block is on a locked layer or will I need to unlock the layer first?

If I need to unlock the layer how do I retrieve the layer the block is on?

The last road block I see is not knowing which layout the block was inserted on.

Will I be able to change the block's layer if the layout that contains the block is not current?

If not, how do I figure out which layout contains the block?

Thanks for any help.

T.Willey
2008-11-10, 08:48 PM
I work with LDT and LDT inserts a block named ACADD_ZZ in paper space to keep track of which project the drawing is associated with. Sometimes that block ends up on a locked layer which causes LDT to display errors.

My goal is to change the ADCADD_ZZ block to layer 0.

I just spent the last 1.5 hours reading the Help and forums and haven't gotten very far. I'm taking baby steps but this is what I have:

(defun c:test ()
; (setq ss1 (ssget "x" '((2 . "addcad_zz"))))
; (setq en (ssname ss1 0))
(setq en (entnext))
(setq ed (entget en)) ; Sets ed to the entity data for entity name en.
(setq ed
(subst (cons 8 "0")
(assoc 8 ed) ; Changes the layer group in ed.
ed ; to layer 0.
)
)
(entmod ed) ; Modifies entity en's layer in the drawing.
)
I got this directly from the help. It works but only on the first object in the drawing (entnext). I tried adding lines 2 and 3 and commenting line 4 but that doesn't work. I get the following error:
; error: bad argument type: lselsetp nil

How do I select the ADCADD_ZZ block and change it's layer?

(setq ss (ssget "x" '((0 . "INSERT") (2 . "ACADD_ZZ"))))



Will it be possible to change the layer of the block while the block is on a locked layer or will I need to unlock the layer first?

You will have to unlock the layer first.



If I need to unlock the layer how do I retrieve the layer the block is on?

The layer name the entity is on is dxf code 8. The help files lists all this information.



The last road block I see is not knowing which layout the block was inserted on.

Doesn't matter if you are using code. If you use the command version, then it matters.



Will I be able to change the block's layer if the layout that contains the block is not current?

Yes.



Thanks for any help.
You're welcome. I hope that is enough to get you going in the right direction.

irneb
2008-11-11, 05:22 AM
E.g.
(defun c:test (/ ss1 en ed lay);Add variables to be local, so it clears from RAM
(setq ss1 (ssget "x" '((2 . "addcad_zz"))))
(setq en (ssname ss1 0))
(setq ed (entget en)) ; Sets ed to the entity data for entity name en.
(setq lay (cdr (assoc 8 ed))) ;Get current layer of object
;; Check if layer is locked
(if (and
(setq lay (tblobjname "LAYER" lay));Get layer entity
(setq lay (entget lay));Get layer data
(> (logand (cdr (assoc 70 lay)) 4) 0);Check if locked
)
(progn
(setq lay (cdr (assoc 2 lay)));Get layer name ... again
(command "-LAYER" "_Unlock" lay "");Unlock layer
)
(setq lay nil);Else set layer name to nil
)
(setq ed
(subst (cons 8 "0")
(assoc 8 ed) ; Changes the layer group in ed.
ed ; to layer 0.
)
)
(entmod ed) ; Modifies entity en's layer in the drawing.
(if lay ;Check if layer was locked
(command "-LAYER" "_LOck" lay "");Lock layer
)

(princ);Ensure that list of data doesn't get written to the command line after finishing
)

jpaulsen
2008-11-12, 07:17 PM
Thanks for the replies. I have not had time to get back on this project. I will post here with my results when I do.

jpaulsen
2008-11-26, 01:27 PM
Thank you for the responses. The additional code that IRNEB added was what I needed to deal with the locked layer.

When I first used IRNEB's code I was getting the same error (; error: bad argument type: lselsetp nil).

So I looked at the code a little closer and found an error in my original code. The block name in line 2 was incorrect. Once I corrected it IRNEB's code worked great. Likewise my code worked after removing the comment from lines 2 and 3 and removing line 4.

Again thanks for the help and thanks for the IF statement. That probably saved me another hour =)

irneb
2008-11-27, 05:38 AM
You're welcome, glad we could help.