Sort through a list

Discussion in 'AutoCAD' started by Chip Harper, Jul 16, 2003.

  1. Chip Harper

    Chip Harper Guest

    Novice Lisper looking for help here.

    I have a utility that I wrote that allows me to select a layer to freeze
    then thaw it later using a short command. At present I'm limited to one
    layer. I've figured out how to use the append function to add the additional
    layers to my list but I'm looking for assistance on how to step through the
    resulting list to thaw the list of layers. I'm thinking use the length
    function to get the number of layers in the list and then a loop using nth
    function to get each layer name in turn. Suggestions appreciated.
     
    Chip Harper, Jul 16, 2003
    #1
  2. Chip Harper

    Paul Turvill Guest

    How about (foreach ...)? Works with any length list:

    (foreach LayName LayList
    (<<process LayName>>)
    );; foreach
    ___
     
    Paul Turvill, Jul 16, 2003
    #2
  3. Chip Harper

    Chip Harper Guest

    Yeah, thats the ticket! Thanks! :)
     
    Chip Harper, Jul 16, 2003
    #3
  4. Chip Harper

    Paul Turvill Guest

    You're welcome, Chip.
    ___
     
    Paul Turvill, Jul 16, 2003
    #4
  5. One thing to bear in mind: if you're just driver the -LAYER command,
    you'd be better served concatenating the list contents and passing all
    the layer names as a single parameter. That way you only freeze once
    instead of N times.
     
    Frank Oquendo, Jul 16, 2003
    #5
  6. Chip Harper

    Chip Harper Guest

    Hummm the plot thickens..... How would I pass multiple layer names as a
    single parameter to the layer command?
     
    Chip Harper, Jul 17, 2003
    #6
  7. Chip Harper

    Chip Harper Guest

    DUH!

    I had no idea you could use pass multiple items seperated by a comma to the
    command. Very Cool indeed. Thanks again. :)
     
    Chip Harper, Jul 17, 2003
    #7
  8. Chip Harper

    BillZ Guest

    You're welcome.
    Another variation:
    (setq lst (list "thislayer" "thatlayer" "anotherlayer"))
    (foreach n lst (setq lay_lst (cons (strcat n ",") lay_lst)))
    (setq lay_lst (apply 'strcat lay_lst))

    Bill
     
    BillZ, Jul 17, 2003
    #8
  9. Chip Harper

    Paul Turvill Guest

    Just like the keyboard. Also accepts wildcards.
    ___
     
    Paul Turvill, Jul 17, 2003
    #9
  10. Chip Harper

    BillZ Guest

    This seems to work fine also: (apply 'strcat (mapcar '(lambda (x)(strcat x delim)) lst))



    Bill
     
    BillZ, Jul 17, 2003
    #10
  11. (setq delim ",")
    ","

    (setq lst '("a" "b" "c"))
    ("a" "b" "c")

    (apply 'strcat (mapcar '(lambda (x)(strcat x delim)) lst))
    "a,b,c,"

    (strlcat delim lst)
    "a,b,c"
     
    Jason Piercey, Jul 17, 2003
    #11
  12. There's a limit on the number of characters that you can
    pass that way, so it's really wiser to issue a separate
    call to the Freeze subcommand for each layer name, since
    doing that does not really cost you much (the changes to
    all layers are not made until you end the layer command
    anyways).
     
    Tony Tanzillo, Jul 17, 2003
    #12
  13. Chip Harper

    BillZ Guest

    And your point is?
     
    BillZ, Jul 17, 2003
    #13
  14. Chip Harper

    Chip Harper Guest

    Never thought to try it (multiple items) via the keyboard before so I got a
    double nugget on that one. ;-)
     
    Chip Harper, Jul 17, 2003
    #14
  15. Chip Harper

    BillZ Guest

    My question: Do you really need the extra code to get rid of it? The layer command recognizes that it is a delimeter and ignores it.

    Bill
     
    BillZ, Jul 17, 2003
    #15
  16. Fine, for the layer command, what about any other use of
    the string?
     
    Jason Piercey, Jul 17, 2003
    #16
  17. Chip Harper

    BillZ Guest

    Jason,
    Not to belabor this any further but..

    What other use would one have for a comma delimited string, other than it being used programically? If your program is set up to read a comma as a delimiter, why would it have trouble with one at the end of the string?
    Am I missing something?



    Bill
     
    BillZ, Jul 17, 2003
    #17
  18. Bill,

    There are other characters than the comma. I frequently use
    (strlcat) to form keywords for (initget) or right click menu
    options for (getkword).... in the instance of (getkword) using
    a "/" as the delimiter, do you really want the prompt to look like
    this?

    (getkword "[A/B/C/]test prompt")

    After all, we are talking "toolbox" functions here, not specific
    to comma delimited strings and the layer command.

    --

    -Jason
    Member of the Autodesk Discussion Forum Moderator Program


    programically? If your program is set up to read a comma as a delimiter, why would it have
    trouble with one at the end of the string?
     
    Jason Piercey, Jul 17, 2003
    #18
  19. Chip Harper

    Paul Turvill Guest

    That (and wildcards) is just one of the reasons I've long been an advocate
    of a layering scheme that uses "families" of layers. For example, in our
    architectural drawings, all of our layers that deal with objects on the
    Foundation Plan begin with the characters "FO"; Main Floor, "MA"; 2nd Floor
    "2N"; etc. So (for example) to thaw or freeze a group of layers we can
    quickly isolate just the view we want with
    -la
    f
    MA*,2N*
    t
    FO*

    etc.

    It's faster than either the layer dialog or LayMan, and works equally well
    from the keyboard or with LISP.
    ___
     
    Paul Turvill, Jul 17, 2003
    #19
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.