Results 1 to 6 of 6

Thread: Change layer of block on locked layer in paper space

  1. #1
    AUGI Addict jpaulsen's Avatar
    Join Date
    2002-04
    Location
    Colorado
    Posts
    2,020
    Login to Give a bone
    0

    Default Change layer of block on locked layer in paper space

    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:
    Code:
    (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.

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Change layer of block on locked layer in paper space

    Quote Originally Posted by jpaulsen View Post
    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:
    Code:
    (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"))))

    Quote Originally Posted by jpaulsen View Post
    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.

    Quote Originally Posted by jpaulsen View Post
    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.

    Quote Originally Posted by jpaulsen View Post
    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.

    Quote Originally Posted by jpaulsen View Post
    Will I be able to change the block's layer if the layout that contains the block is not current?
    Yes.

    Quote Originally Posted by jpaulsen View Post
    Thanks for any help.
    You're welcome. I hope that is enough to get you going in the right direction.

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Change layer of block on locked layer in paper space

    E.g.
    Code:
    (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
    )

  4. #4
    AUGI Addict jpaulsen's Avatar
    Join Date
    2002-04
    Location
    Colorado
    Posts
    2,020
    Login to Give a bone
    0

    Default Re: Change layer of block on locked layer in paper space

    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.

  5. #5
    AUGI Addict jpaulsen's Avatar
    Join Date
    2002-04
    Location
    Colorado
    Posts
    2,020
    Login to Give a bone
    0

    Default Re: Change layer of block on locked layer in paper space

    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 =)

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Change layer of block on locked layer in paper space

    You're welcome, glad we could help.

Similar Threads

  1. Change One Or Two Block Layer(s)
    By omorah in forum AutoCAD Customization
    Replies: 4
    Last Post: 2010-08-30, 12:09 PM
  2. Station tic color seems to be dependent on current layer in paper space
    By myork.194843 in forum AutoCAD Civil 3D - Alignments
    Replies: 3
    Last Post: 2009-06-22, 06:49 PM
  3. Change Block Layer
    By Mac Demer in forum AutoCAD General
    Replies: 6
    Last Post: 2009-04-06, 06:13 PM
  4. Replies: 6
    Last Post: 2007-05-30, 05:45 PM
  5. Replies: 7
    Last Post: 2006-10-23, 04:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •