ajs Posted June 7, 2009 Posted June 7, 2009 Hi there, Our shop is running both legacy Intellicad and Autocad with different activities on different stations so at times I have to be careful in my lisp programming regarding cross-compatability issues. This particular circumstance is for my own use though, running Acad 2009 of which I purchased a single seat earlier this year. Here's my situation: I have a selection set to identify text with a certain height: (setq FE_01 (ssget "_X" '((0 . "Text")(40 . 0.125)))) What I have been trying to do with no success is figure out how to have a variable value for the text height portion of the selection set. For example, If I create the number variable: (setq AAA 0.125) I cannot substitute that variable within the selection set, i.e, (setq FE_01 (ssget "_X" '((0 . "Text")(40 . AAA)))) If I try, I get a bad selection set message. I then tried SUBST but was unsuccessful: (setq FE_01 (ssget "_X" '((0 . "Text")(SUBST 'AAA '0.125 '(40 . 0.125))))) I had hoped the SUBST function would transfer the AAA variable into the dotted pair but that didn't work out. (I know I probably botched the syntax on the SUBST) I've done a search but I can't seem to find this particular problem addressed. There was some info on AfraLisp and I felt that I was close to understanding it but I couldn't quite pull it off. Although my current programming skills are weak,I have to confess that there's something about Lisp that's very attractive and I enjoy learning it. I wish it was more common in other applications Any advice on my current dilema would be greatly appreciated. Thank you AJS Quote
jammie Posted June 7, 2009 Posted June 7, 2009 Hey AJS The problem lies with the quote used for the selection set filter (setq FE_01 (ssget "_X" '((0 . "Text")(40 . 0.125)))) To pass a variable value you need to use list (setq FE_01 (ssget "_X" (list (cons 0 "Text")(cons 40 AAA)))) For a bit more info on it see the following thread http://www.cadtutor.net/forum/showthread.php?t=36514 Regards Jammie Quote
Lee Mac Posted June 7, 2009 Posted June 7, 2009 When you create a Filter List for an SSGET expression, there are many ways to structure the list, and understanding the differences is crucial. Firstly note that a list can be created by either: (list 1 2 3) or '(1 2 3) Both of which represent the same thing. However, the interpreter will interpret these two expressions in two different ways. With the first, the list function tells the interpreter to evaluate each argument passed to it and return a list containing all the arguments passed. However, with the second arrangement, the quote symbol (or apostrophe) will tell the interpreter not to evaluate any of the expressions within the statement following the apostrophe. Which is why the apostrophe is used in mapcar: (mapcar '+ (list 1 2 3) (list 2 3 4)) Returns: (3 5 7) The apostrophe in this case tells the interpreter that the function + is not to be evaluated, but instead is to be passed as an argument to the mapcar function. So, getting back to your problem at hand. When you create a filter list with "known" elements, for example: (ssget '((0 . "TEXT") (40 . "2.5))) The list supplied is not evaluated, but is just passed as an argument to the ssget function (because of the apostrophe). So no variables within the list will be evaluated. So to evaluate variables, we need to supply the interpreter with functions that tell it to evaluate out arguments: (setq hgt 0.125) (ssget (list (cons 0 "TEXT") (cons 40 hgt))) Now, providing our variable holds a value of the correct format, (in this case a Real), the filter list will be constructed and evaluated correctly. Alternatively, you can combine these options: (setq hgt 0.125) (ssget (list '(0 . "TEXT") (cons 40 hgt))) As the '(0 . "TEXT") part is just treated as a list argument and passed to the list function. However this will NOT work: (setq hgt 0.125) (ssget '((cons 0 "TEXT") (cons 40 hgt))) As the cons functions will not be evaluated, due to the presence of the apostrophe. If you have any questions about any of the information I have posted, just ask. Cheers, Lee Quote
jammie Posted June 7, 2009 Posted June 7, 2009 If you did want to use subst then something like this would work ;;Create a simple filter list (setq TextFilter '((0 . "Text")(40 . 1.125))) ;;Assign a new vaule (setq AAA 0.25) ;;Create a new selection filter (setq NewFilter (subst (cons 40 AAA)(ASSOC 40 TextFilter) TextFilter)) (setq FE_01 (ssget "_X" NewFilter)) but using LIST would be the preferred option in this case (setq FE_01 (ssget "_X" (list (cons 0 "Text")(cons 40 AAA)))) Quote
jammie Posted June 7, 2009 Posted June 7, 2009 Jammie beat me to it A far more thorough explaination by you though, nice job Quote
ajs Posted June 7, 2009 Author Posted June 7, 2009 Thank you very much; I think this is one of the best informative posts for my current knowledge level that I've read. I've always felt murky when it comes to how "quote" operates. This is very helpful. While I've got you guys, one thing that I've never quite been able to wrap my head around is how the exclamation point functions in displaying a variable's value. As a test, the exclamation point has always worked great if I'm on the screen, typing at the command line but when I've used it within a command in Lisp, it's been hit or miss and I haven't been able to determine a pattern as to the principle of why it does or does not work. Is the exclamation point an integral part of Lisp that has a set of rules or is it a hybrid created for testing purposes? Again, much thanks AJS Quote
Lee Mac Posted June 7, 2009 Posted June 7, 2009 I wouldn't use the exclaimation mark within a LISP, but rather print, which should accomplish the same thing Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.