combining the LISPS into single lisp

combining the LISPS into single lisp

Anonymous
Not applicable
1,437 Views
12 Replies
Message 1 of 13

combining the LISPS into single lisp

Anonymous
Not applicable

How can i combine these attached three lisps into single one so that i can use single command to select between three.......for eg...if i can activate all wall l,wall x,wall t by entering LTX and selecting between them.....THANKS IN ADVANCE....

 

 

 

QUOTE:
The hands that serve are holier than the lips that pray.-Robert Green

0 Likes
Accepted solutions (4)
1,438 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

This attached file does it i.e combines the three lisps into 1 but the wall-X is not working......Can anyone give a solution to this file........

0 Likes
Message 3 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> This attached file does it i.e combines the three lisps into 1 

Don't use the

     (defun c:walls (/ hellow)

around the single functions.

So remove the first line as well as the last 3 lines (which I guess you added).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 4 of 13

Anonymous
Not applicable

Thanks for the reply sir... But i didn't understand as i am new to lisp... i downloaded that combined lisp from a site and i found that wall-x isnt working...Thats why i asked for solution here....Can you please help me out,sir?

0 Likes
Message 5 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> i downloaded that combined lisp from a site and i found that wall-x isnt working

Well, in that case please ask there ... where you have downloaded the file. It's not so easy (without know what you mean by "not working") to analyse code another guy wrote and modify it.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 6 of 13

Anonymous
Not applicable
Accepted solution

I attached the .Lsp.
Those were the lines I made the modification.

	(initget "L T X")
	(setq hellow (cond ((getkword "\nWhat shape do you want [L/T/X]? : <L>"))
			   ("L")))
	(if (or (= hellow "L") (= hellow ""))
	  (wall-l)
	  (if (= hellow "T")
	    (wall-t)
	    (if (= hellow "X")
	      (c:wall-x)
	      )
	    )
	  )
  )

 

Message 7 of 13

Anonymous
Not applicable

Not only your post helped me it saved me my friend.....Thank you for helping me out.....If only i could return the favor to you..Anyway may my prayers be with you...God bless you my friend...

Message 8 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

	(initget "L T X")
	(setq hellow (cond ((getkword "\nWhat shape do you want [L/T/X]? : <L>"))
			   ("L")))
	(if (or (= hellow "L") (= hellow ""))
	  (wall-l)
	  (if (= hellow "T")
	    (wall-t)
	    (if (= hellow "X")
....

 


Just a comment or two....

 

The red part above means that if the User hits Enter at the prompt, the 'hellow' variable will be set to "L".  That means that it will always  be either "L" or "T" or "X" no matter what, so the magenta part can never be True, which means that the (or) function is extraneous.

 

And that kind of sequence of (if) functions nested inside each other  is just the situation that the (cond) function is designed to handle more concisely:

(initget "L T X")
(setq hellow
(cond
((getkword "\nWhat shape do you want [L/T/X]? : <L>")) ("L"); [if User hits Enter so above returns nil]
)
) (cond
((= hellow "L") (wall-l))
((= hellow "T") (wall-t)) ((= hellow "X") (c:wall-x)) )
Kent Cooper, AIA
Message 9 of 13

Anonymous
Not applicable

Very very good @Kent1Cooper
It's good to learn things like this with you, Used COND code is much more elegant.

 

 

Message 10 of 13

Anonymous
Not applicable

Does this condn make any difference to the functionality of the lisp ??

Can u tell me which is better...using ifs or condn.....

0 Likes
Message 11 of 13

Anonymous
Not applicable
Accepted solution

@Anonymous Both work.
But with COND, it will look more elegant, I've attached the correct .LISP

 

 

 

Message 12 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

Does this condn make any difference to the functionality of the lisp ??

Can u tell me which is better...using ifs or condn.....


No, it wouldn't make any difference to the functionality.

 

Which is better depends on circumstances.  The (if) function takes a 'then' expression [what to do if the test part returns something other than nil] and an 'else' expression [what to do if it returns nil, which you can omit if you don't want it to do anything].  So it's a two-situations-at-the-most operation, concerned only with whether a single test is satisfied.  The (cond) function can look at a whole series of any number of possible situations, and they don't even need to be related tests, and will do whatever it's instructed for the first of those that is satisfied, and then stop.

 

@Anonymous's structure with the (if) functions nested  inside each other takes some more code, but is at least better than what you sometimes see -- a series of independent (if) functions testing the same thing for possible values, with 'then' expressions but no 'else' expressions for each, such as:
(if (= hellow "L") (wall-l))
(if (= hellow "T") (wall-t))
(if (= hellow "X") (c:wall-x))

The drawback in that is that even if 'hellow' is set to "L", and the first  (if) function finds that to be the case, and it does the (wall-l) thing in response, the routine still has to go on and test for each of the rest of the possible values, even though none of those tests will be satisfied.  That's the big benefit of (cond), especially with a large number of possible conditions -- as soon as it finds a test satisfied, it acts on it and doesn't look at the rest of them at all.  That's effectively what happens in @Anonymous's nested-(if)s approach -- when one is satisfied, it won't look at the rest -- but it's wordier than using (cond), and gets more so the more conditions are involved.

 

Just for fun, here's another way to go about it, after the 'hellow' variable has been set, not using either (if) or (cond):

 

(eval (cdr (assoc hellow '(("L" wall-l) ("T" wall-t) ("X" C:wall-x)))))
 

Kent Cooper, AIA
Message 13 of 13

Anonymous
Not applicable
Accepted solution

Thank you,Sir!

0 Likes