Jump to content

Conditional Statement


uuoo10levi

Recommended Posts

I'm trying to figure out what I would understand to be something simple. I want to create a lisp that I can tell it to draw 3 lines and then I can specify if it goes to the left or to the right. Here is the basic of what I have so far.

 

(defun c:ju()

 (setq oldosmode (getvar "osmode"))
 (setq oldlayer (getvar "clayer"))

 (setq	p1  (getpoint "\nPick Top Point:")
p2  (getpoint "\nPick Bottom Point:")
lvl (getint "\nJumper Level: (1,2,3,4...)")
 )

 (setq	p3 (list (+ (car p1) (* lvl 0.09375))
	 (- (cadr p1) (* lvl 0.03125))
   )
 )
 (setq	p4 (list (+ (car p2) (* lvl 0.09375))
	 (+ (cadr p2) (* lvl 0.03125))
   )
 )
 (setvar "clayer" "text0")

 (command "line" p1 p3 "")
 (command "line" p2 p4 "")
 (command "line" p3 p4 "")

 (setvar "clayer" oldlayer)
 (setvar "osmode" oldosmode)
)

 

This is what it creates

 

jumper.png

 

Now, that works great and I need is to specify that I would want that jumper to go to the right or the left of the 2 white lines. I could use some help.

Link to comment
Share on other sites

Do you want link this??

 

(defun c:ju()

 (setq oldosmode (getvar "osmode"))
 (setq oldlayer (getvar "clayer"))

 (setq	p1  (getpoint "\nPick Top Point:")
     	p2  (getpoint "\nPick Bottom Point:")
      lvl (getint "\nJumper Level: (1,2,3,4...)")
 )
 (setq q (strcase (getstring "\nLeft/Right[Enter:R]:")))
 (if (eq "" q) (setq q "R"))
 (cond
  ((eq q "R") (setq opt "+"))
  ((eq q "L") (setq opt "-"))
 )
 (setq	p3 (list ((eval (read opt)) (car p1) (* lvl 0.09375))
	 (- (cadr p1) (* lvl 0.03125))
   )
 )
 (setq	p4 (list ((eval (read opt)) (car p2) (* lvl 0.09375))
	 (+ (cadr p2) (* lvl 0.03125))
   )
 )
 (setvar "clayer" "text0")

 (command "line" p1 p3 "")
 (command "line" p2 p4 "")
 (command "line" p3 p4 "")

 (setvar "clayer" oldlayer)
 (setvar "osmode" oldosmode)
)[/color]

 

 

I'm trying to figure out what I would understand to be something simple. I want to create a lisp that I can tell it to draw 3 lines and then I can specify if it goes to the left or to the right. Here is the basic of what I have so far.

 

(defun c:ju()

 (setq oldosmode (getvar "osmode"))
 (setq oldlayer (getvar "clayer"))

 (setq	p1  (getpoint "\nPick Top Point:")
p2  (getpoint "\nPick Bottom Point:")
lvl (getint "\nJumper Level: (1,2,3,4...)")
 )

 (setq	p3 (list (+ (car p1) (* lvl 0.09375))
	 (- (cadr p1) (* lvl 0.03125))
   )
 )
 (setq	p4 (list (+ (car p2) (* lvl 0.09375))
	 (+ (cadr p2) (* lvl 0.03125))
   )
 )
 (setvar "clayer" "text0")

 (command "line" p1 p3 "")
 (command "line" p2 p4 "")
 (command "line" p3 p4 "")

 (setvar "clayer" oldlayer)
 (setvar "osmode" oldosmode)
)

 

This is what it creates

 

[ATTACH]39491[/ATTACH]

 

Now, that works great and I need is to specify that I would want that jumper to go to the right or the left of the 2 white lines. I could use some help.

Edited by kraz
Link to comment
Share on other sites

Easiest way is to not have to type an answer add pick left or right as a 3rd getpoint using mouse is faster, then do one routine just need a swap end points test for left or right.

 

(setq pt1 (getpoint "\npick 1st point to place pit : "))
(setq pt2 (getpoint "\nPick 2nd point for orientation"))
(setvar "osmode" 0)
(setq pt7 (getpoint "\Pick pt on pit side : "))
(setq ang (angle pt1 pt2))
(setq ang5 (angle pt2 pt7))
(setq diffang (- ang ang5))
(if (> diffang 1.5707) 
(setq ang2 (- ang 1.570796))
(setq ang2 (+ ang 1.570796))
)

 

ps dont upset moderator put code in tags

Link to comment
Share on other sites

Do you want faster than type "L" or "R" ?

then, pointing left or right of p1

(defun c:ju()

(setq oldosmode (getvar "osmode"))
(setq oldlayer (getvar "clayer"))

(setq	p1 (getpoint "\nPick Top Point:")
p2 (getpoint "\nPick Bottom Point:")
lvl (getint "\nJumper Level: (1,2,3,4...)")
)
(setq q (getpoint p1 "\nDirection:"))
(if (>= (car q) (car p1))
(setq opt "+")
(setq opt "-")
)

(setq	p3 (list ((eval (read opt)) (car p1) (* lvl 0.09375))
(- (cadr p1) (* lvl 0.03125))
)
)
(setq	p4 (list ((eval (read opt)) (car p2) (* lvl 0.09375))
(+ (cadr p2) (* lvl 0.03125))
)
)
(setvar "clayer" "text0")

(command "line" p1 p3 "")
(command "line" p2 p4 "")
(command "line" p3 p4 "")

(setvar "clayer" oldlayer)
(setvar "osmode" oldosmode)
)

Edited by kraz
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...