Sort through a list

Chip Harper

Usenet Archive
Joined
Jan 17, 2000
Messages
409
Reaction score
0
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.
 
How about (foreach ...)? Works with any length list:

(foreach LayName LayList
(<<process LayName>>)
);; foreach
___
 
Chip said:
Yeah, thats the ticket! Thanks! :-)

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.
 
Hummm the plot thickens..... How would I pass multiple layer names as a single parameter to the layer command?
 
DUH!

I had no idea you could use pass multiple items seperated by a comma to the command. Very Cool indeed. Thanks again. :-)
 
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
 
This seems to work fine also: (apply 'strcat (mapcar '(lambda (x)(strcat x delim)) lst))

Bill
 
(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"
 
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).
 
Never thought to try it (multiple items) via the keyboard before so I got a double nugget on that one. ;-)
 
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
 
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
 
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.

BillZ said:
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?
 
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.
___
 

Latest threads

Back
Top