Layer List

Discussion in 'AutoCAD' started by Scott, Aug 5, 2003.

  1. Scott

    Scott Guest

    Hi

    I was wondering how I could go about obtaining a list off all the layer
    names in the current drawing? I will then need to assign this list to a
    single variable for Vlisp.

    Thanks
     
    Scott, Aug 5, 2003
    #1
  2. Scott

    R.K. McSwain Guest

    Here is one way:

    (defun laylist ( / llist lnlist)
    (setq llist (tblnext "layer" t))
    (while llist
    (setq lnlist (cons (cdr (assoc 2 llist)) lnlist))
    (setq llist (tblnext "layer"))
    )
    (acad_strlsort lnlist)
    )

    Then -> (setq a (laylist))
     
    R.K. McSwain, Aug 5, 2003
    #2
  3. Scott

    R.K. McSwain Guest

    Yes, you are correct. That does work.
    ......until you run it the second time.
     
    R.K. McSwain, Aug 5, 2003
    #3
  4. A minor change:

    (defun laylist (/ llist lnlist)
    (while (setq llist (tblnext "layer" (not llist)))
    (setq lnlist (cons (cdr (assoc 2 llist)) lnlist))
    )
    )


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | > How about this:
    | >
    | > (defun laylist (/ llist lnlist)
    | > (while (setq llist (tblnext "layer"))
    | > (setq lnlist (cons (cdr (assoc 2 llist)) lnlist))
    | > )
    | > )
    |
    | Yes, you are correct. That does work.
    | .....until you run it the second time.
     
    R. Robert Bell, Aug 5, 2003
    #4
  5. Scott

    Scott Guest

    Wow! Thank you everybody for your help with this!

     
    Scott, Aug 5, 2003
    #5
  6. Try this. Works for any table, not just the layer table.

    ; author - Puckett
    ; - string, valid table name
    ; returns each item name from
    (defun table (s / d r)
    (while (setq d (tblnext s (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
    )
    (reverse r)
    )

    Examples:
    (setq myListOfLayerNames (table "layer"))

    (setq myListOfBlockNames (table "block"))

    (setq myListOfViewNames (table "view"))

    etc....
     
    Jason Piercey, Aug 5, 2003
    #6
  7. Did that limitation exist in the original routine?
     
    Frank Oquendo, Aug 5, 2003
    #7
  8. Scott

    R.K. McSwain Guest

    No, why?
     
    R.K. McSwain, Aug 6, 2003
    #8
  9. Scott

    R.K. McSwain Guest

    I'm lost. :(

    Frank *is* the one who posted the version that didn't work (after the first time it was run).
     
    R.K. McSwain, Aug 6, 2003
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.