| Author |
Message |
Greg
Joined: 16 Jun 2005
Posts: 5
|
Posted:
Thu Jun 16, 2005 1:21 pm Post subject:
Adding two variables (how to) |
|
|
The lisp routine is as follows:
draws plan details using using using input
(defun c:b3 ()
(setq p9 (getint "Please enter the width of Poured Concrete:" ))
(setq p1 (append '(0 0)))
(setq p2 (append '(0 20)))
(setq p3 (append '(0 20)))
(setq p4 (append '(20 20)))
(setq p5 (nth 0 '(0 20)))
(setq p6 (nth 1 '(0 20)))
(setq p7 (nth 0 '(20 20)))
(setq p8 (nth 1 '(20 20)))
(setq p10 (+ p5 p9))
(setq p11 (- p6 p9))
(setq p12 (+ p5 p9))
(setq p13 (- p8 p9))
(setq p14 (+ p5 p9))
(setq p15 (- p8 p9))
(setq p16 (- p7 p9))
(setq p17 (- p8 p9))
(setq p18 (append '(p10 p11)))
(setq p19 (append '(p12 p13)))
(setq p20 (append '(p14 p15)))
(setq p21 (append '(p16 p17)))
(command "_line" p1 p2 p3 p4 "")
(command "_line" p18 p19 p20 p21 "")
What I am trying to do is have setq p10 recognize that it is adding 'p5' and 'p9' together to form the next part of the routine. Is this the right way of doing this. The program ends after it draws the first line. If anyone can help me out, it would be greatly appreciated.
|
|
| Back to top |
|
 |
CarlB
Joined: 27 Sep 2005
Posts: 52
|
Posted:
Wed Sep 28, 2005 9:31 pm Post subject:
re:Adding two variables (how to) |
|
|
Hi Greg,
A few 'quirks' in your code...
(setq p1 (append '(0 0))) can be instead
(setq p1 '(0 0))
Your p2 and p3 are set to the same values.
(setq p5 (nth 0 '(0 20))) is setting p5 to the first item in the list, 0, so it's the same as (setq p5 0)
You can't simply add two coordinate (lists) together with '+
instead, (setq p10 (mapcar '+ p5 p9))
this adds each x value, y value, etc together.
After running the routine, you can type on the command line excalamation point and variable name to see what the value is, this will help you troubleshoot. For example typing "!p18" (without quotes) would tell you what program calculated for that value.
Hope that helps some, come back with revised code & more questions! |
|
| Back to top |
|
 |
Adesu
Joined: 20 Jul 2005
Posts: 31
|
Posted:
Thu Sep 29, 2005 12:47 am Post subject:
Re: Adding two variables (how to) |
|
|
Hi Greg,maybe what do you want as like this
| Code: | (defun c:b3 ()
(setq p9 (getint "Please enter the width of Poured Concrete:" ))
(setq p1 '(0 0))
(setq p2 '(20 0))
(setq p3 '(20 20))
(setq p4 '(0 20))
(setq p5 (nth 0 p4))
(setq p6 (nth 1 p4))
(setq p7 (nth 0 p3))
(setq p8 (nth 1 p3))
(setq p10 (+ p5 p9))
(setq p11 (- p6 p9))
(setq p12 (+ p5 p9))
(setq p13 (- p8 p9))
(setq p14 (+ p5 p9))
(setq p15 (- p8 p9))
(setq p16 (- p7 p9))
(setq p17 (- p8 p9))
(setq p18 (list p10 p11))
(setq p19 (list p12 p13))
(setq p20 (list p14 p15))
(setq p21 (list p16 p17))
(command "_line" p1 p2 p3 p4 "")
(command "_line" p18 p19 p20 p21 "")
) |
| Greg wrote: | The lisp routine is as follows:
draws plan details using using using input
(defun c:b3 ()
(setq p9 (getint "Please enter the width of Poured Concrete:" ))
(setq p1 (append '(0 0)))
(setq p2 (append '(0 20)))
(setq p3 (append '(0 20)))
(setq p4 (append '(20 20)))
(setq p5 (nth 0 '(0 20)))
(setq p6 (nth 1 '(0 20)))
(setq p7 (nth 0 '(20 20)))
(setq p8 (nth 1 '(20 20)))
(setq p10 (+ p5 p9))
(setq p11 (- p6 p9))
(setq p12 (+ p5 p9))
(setq p13 (- p8 p9))
(setq p14 (+ p5 p9))
(setq p15 (- p8 p9))
(setq p16 (- p7 p9))
(setq p17 (- p8 p9))
(setq p18 (append '(p10 p11)))
(setq p19 (append '(p12 p13)))
(setq p20 (append '(p14 p15)))
(setq p21 (append '(p16 p17)))
(command "_line" p1 p2 p3 p4 "")
(command "_line" p18 p19 p20 p21 "")
What I am trying to do is have setq p10 recognize that it is adding 'p5' and 'p9' together to form the next part of the routine. Is this the right way of doing this. The program ends after it draws the first line. If anyone can help me out, it would be greatly appreciated. |
|
|
| Back to top |
|
 |
|
|
|
|