Results 1 to 7 of 7

Thread: Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2012-04
    Posts
    1
    Login to Give a bone
    0

    Default Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

    Hi

    This is my first post, my name is Lorenzo I’m living in northern Quebec in Canada. I’m a Mechanical designer & draftsmen for the last 18 years & recently got a new job where they only use 2d & since I use 3d Inventor for the last 10 years I had to take my old routine from the mothballs & put them back to work.

    My problems is that i do not find my autolisp class note from the 90 & now I need to built a new Layer manipulation routine from scratch & I just don’t remember how.! Well I remember many parts but not enough so I pick-up some lines from existing routine

    The proposed routine will go like this

    1-Selection of objects & extraction of layer name of each object with something like:

    (setq A (cdr (assoc 8 (entget (car (entsel "\nPick entity to keep layer on: "))))))

    2-Building a list of the layer name from previous selection

    That where I jam!

    4-Off or freeze of all layer with something like

    (command "_-layer" "_off" "*" "" "")

    5-On or thaw of the list of the previously selected item

    (command "_-layer" "_on" "???????list generated with item 2???????" ""))



    My guess that I should use ssget instead of enget but I’m not sure & I don’t remember how to use it anyway!


    Any help would be appreciated

    Thanks

    Lorenzo Di Marco

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

    For fun...

    Code:
    (defun c:FOO  ( / ss i e layer layers)
      (vl-load-com)
      (if (setq ss (ssget))
        (progn
          (setq i -1)
          (while (and (setq e (ssname ss (setq i (1+ i))))
                      (not (vl-position
                             (setq layer (cdr (assoc 8 (entget e))))
                             layers)))
            (setq layers (cons layer layers)))
          (command "._-layer"
                   "freeze"
                   "*"
                   "thaw"
                   (strcat
                     (getvar 'clayer)
                     ","
                     (vl-string-right-trim
                       ","
                       (apply 'strcat
                              (mapcar '(lambda (x) (strcat x ",")) layers))))
                   "")))
      (princ))
    Last edited by RenderMan; 2012-05-01 at 06:49 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

    Also, for simplicity...

    Code:
    (defun c:FOO2 ()
      (command "layiso" "settings" "off" "off"))
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

    Hi .

    I am not sure if I got you well , so here is one try to put a list of selection set's layers off .

    Code:
    (defun c:Test (/ ss i sn lst)
      (vl-load-com)
    ;;; Tharwat 01. May. 2012 ;;;
      (cond ((not acdoc)
             (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
            )
      )
      (if (setq ss (ssget))
        (repeat (setq i (sslength ss))
          (setq sn (ssname ss (setq i (1- i))))
          (if (not (member (cdr (assoc 8 (entget sn))) lst))
            (progn
              (setq lst (cons (cdr (assoc 8 (entget sn))) lst))
              (vla-put-layeron
                (vla-item (vla-get-layers
                            acdoc
                          )
                          (cdr (assoc 8 (entget sn)))
                )
                :vlax-false
              )
            )
          )
        )
        (princ)
      )
      (princ)
    )

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

    Quote Originally Posted by Tharwat View Post
    I am not sure if I got you well , so here is one try to put a list of selection set's layers off .
    Tharwat, I believe the OP is wanting to freeze all layers except for those in the selection set (similar to LAYISO command).
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

    Quote Originally Posted by RenderMan View Post
    Tharwat, I believe the OP is wanting to freeze all layers except for those in the selection set (similar to LAYISO command).
    Thanks Renderman .

    Here is my try again .....

    Code:
    (defun c:Test (/ ss i sn lst l)
      (vl-load-com)
    ;;; Tharwat 01. May. 2012 ;;;
      (cond ((not acdoc)
             (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
            )
      )
      (if (setq ss (ssget))
        (progn
          (repeat (setq i (sslength ss))
            (setq sn (ssname ss (setq i (1- i))))
            (if (not (member (cdr (assoc 8 (entget sn))) lst))
              (setq lst (cons (cdr (assoc 8 (entget sn))) lst))
            )
          )
          (while (setq l (tblnext "LAYER" (null l)))
            (if (and (not (member (cdr (assoc 2 l)) lst))
                     (not (eq (getvar 'clayer) (cdr (assoc 2 l))))
                )
              (vla-put-freeze
                (vla-item (vla-get-layers acdoc) (cdr (assoc 2 l)))
                :vlax-true
              )
            )
          )
        )
        (princ)
      )
      (princ)
    )

  7. #7
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Need help to creating a list of layer (LAYER1,LAYER2,LAYER3,…….) from a selection of entity

    Tharwat,

    Rather than iterating the SelectionSet, then the Layer Table, then the Layers Collection (vla), why not simply iterate the SelectionSet, then the Layers Collection?

    Again, for the stated task, the LayIso Command is all that is needed, IMO.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. entity selection
    By mdsalman2003 in forum AutoLISP
    Replies: 1
    Last Post: 2010-06-30, 08:52 PM
  2. Sub entity slection within a selection set?
    By voigtmark in forum AutoLISP
    Replies: 5
    Last Post: 2010-03-02, 05:29 PM
  3. Draft by Layer vs By Entity
    By simon_t_hall in forum CAD Standards
    Replies: 14
    Last Post: 2008-05-15, 04:32 PM
  4. AutoCAD 2008 - Iterate through an entity list
    By cgerhardt in forum AutoLISP
    Replies: 1
    Last Post: 2007-04-30, 06:21 AM
  5. Add last entity created to selection set
    By cgerhardt in forum VBA/COM Interop
    Replies: 2
    Last Post: 2006-11-16, 08:36 PM

Posting Permissions

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