need help in LISP -

need help in LISP -

miroslav.pristov
Advocate Advocate
407 Views
3 Replies
Message 1 of 4

need help in LISP -

miroslav.pristov
Advocate
Advocate

hello all i presume this is easy but for me it isnt 🙂

 

Can Someone help me in this lisp i need few lines here and what i need is eplained in bolded text on place where i want that lines 

 

(defun C:TP1()
(setq tac1 (getpoint "\n First point A "))
(setq tac2 (getpoint "\n Second point B "))
(setq a (getreal "\n Insert dimension a: "))
(setq b (getreal "\n Insert dimension b: "))
(setq c (getreal "\n Insert dimension c: "))

 

Question : "This is a true" . if it is true i only type enter (ENTER), if not, i type n and then enter (n ENTER)


(setq rast (distance tac1 tac2))
(command "ucs" "3" tac1 tac2 "")
(setq t1 (list (- c) a 0))
(setq t2 (list (+ rast c) a 0))
(setq t3 (list (+ rast c) (- b) 0))
(setq t4 (list (- c) (- b) 0))

(command "osnap" "none")


(command "pline" t1 t2 t3 t4 t1 "") <---- start this line if answer is yes (ENTER)

(command "line" t1 t3 "")  <---- start this line if question is no (n ENTER)


(command "osnap" "END,MID,INT,EXT,APP,CEN,NOD,QUA,INS,PER,TAN,NEA,PAR" "")
(command "ucs" "w")

 

thank you

0 Likes
408 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

Like that?

 

(all sysvar should be the same as routine started. even after error. so "_none" is easier unless you have *error* function)

 

(defun C:TP1 ( / tac1 tac2 rast a b c)
  
  (initget 1)
  (setq tac1 (getpoint "\n First point A "))
  (initget 1)
  (setq tac2 (getpoint "\n Second point B "))

  (setq rast (distance tac1 tac2))

  (command "_.ucs" "3" tac1 tac2 "")
  
  (if (and (setq a (getreal "\n Insert dimension a <skip>: "))
	   (setq b (getreal "\n Insert dimension b: "))
	   (setq c (getreal "\n Insert dimension c: ")))
    (command "_.pline"
	     "_none" (list (- c) a 0)
	     "_none" (list (+ rast c) a 0)
	     "_none" (list (+ rast c) (- b) 0)
	     "_none" (list (- c) (- b) 0)
	     "_close")
    (command "_.line"
	     "_none" (list (- c) a 0)
	     "_none" (list (+ rast c) (- b) 0)
	     ""))
    
  (command "_.ucs" "_p")
  (princ)
)
0 Likes
Message 3 of 4

miroslav.pristov
Advocate
Advocate

thanks for answer, but i think you dont understand me, i didnt really want to change the lisp 

 

Why? because it is a part of bigger one i have in here http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/need-help-on-this-drawing-lisp-layers...

 

The question "This is a true" i wrote in this sample is not that what i want actually. i ll will change the text latter and the lisp too, i just want to see how if command works because i m new in this programming. So can you change it like what i want to have. 

 

like as I type a, b, c, i want the to have question with yes or no option (if i type enter its always yes, if type n and enter then no). if yes it will draw polyline if no it will draw line.

 

By the way, if you have time, can you help me with those problem i linked above with orientation of dimension lines. dont know what to add in LISP to draw lines on the way i want. Some dimension text are upside down. I have some sugestions from some guy but i dont know how to apply that in LISP

0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

Then see this screen capture to learn how to trace values of varibales. 

Type VLIDE to run the editor.

 

See below how to make yes or no question. And read the comments.

 

Spoiler
(defun C:TP1()
  (setq tac1 (getpoint "\n First point A "))
  (setq tac2 (getpoint "\n Second point B "))
  (setq a (getreal "\n Insert dimension a: "))
  (setq b (getreal "\n Insert dimension b: "))
  (setq c (getreal "\n Insert dimension c: "))


  (initget "Yes No")
  (setq flag (getkword "Is this a true? [Yes/No] <Yes>: "))   ;if you hit Enter then flag=nil. if you type "Y" then flag="Yes". if you type "n" then flag="No" (see initget in help)
  
  ;Question : "This is a true" . if it is true i only type enter (ENTER), if not, i type n and then enter (n ENTER)
  
  (setq rast (distance tac1 tac2))
  (command "ucs" "3" tac1 tac2 "")
  (setq t1 (list (- c) a 0))
  (setq t2 (list (+ rast c) a 0))
  (setq t3 (list (+ rast c) (- b) 0))
  (setq t4 (list (- c) (- b) 0))
  
  (command "osnap" "none")

  (if (/= flag "No")
    (command "pline" t1 t2 t3 t4 t1 "") ;<---- start this line if answer is yes (ENTER)
    (command "line" t1 t3 "")) 		;<---- start this line if question is no (n ENTER)
  
  (command "osnap" "END,MID,INT,EXT,APP,CEN,NOD,QUA,INS,PER,TAN,NEA,PAR" "")
  (command "ucs" "w")
)

 ; or -------------------------------------------------------------------------------------------------------------------------

(defun C:TP1()
  (setq tac1 (getpoint "\n First point A "))
  (setq tac2 (getpoint "\n Second point B "))
  (setq a (getreal "\n Insert dimension a: "))
  (setq b (getreal "\n Insert dimension b: "))
  (setq c (getreal "\n Insert dimension c: "))
  
  (setq rast (distance tac1 tac2))
  (command "ucs" "3" tac1 tac2 "")
  (setq t1 (list (- c) a 0))
  (setq t2 (list (+ rast c) a 0))
  (setq t3 (list (+ rast c) (- b) 0))
  (setq t4 (list (- c) (- b) 0))
  
  (command "osnap" "none")
  
  (initget "Yes" "No")
  (if (/= "No" (getkword "Is this a true? [Yes/No] <Yes>: ")) ; i think it does not change a thing if you your quetion move here.
    (command "pline" t1 t2 t3 t4 t1 "") 	;<---- start this line if question is no (n ENTER)
    (command "line" t1 t3 ""))			;<---- start this line if answer is yes (ENTER)
  
  (command "osnap" "END,MID,INT,EXT,APP,CEN,NOD,QUA,INS,PER,TAN,NEA,PAR" "")
  (command "ucs" "w")

)
0 Likes