• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

use a variable as a coordinate for a point

  • Thread starter Thread starter Edo89
  • Start date Start date

Edo89

Guest
Hello everyone,
I just started using autolisp and came across this problem (which I am sure will be banal for many):
I have a p1 point, I extracted the x coordinate with the command (car p1); now I want to generate a p2 point that has as coordinate x the same of p1 and the coordinate y different. if I write for example:
(setq p1(10 50))
(setq x (car p1))
(setq p2'(x 20))

I really can't use p2 as a point to generate a line... what do I have to do?
 
Thank you so much!

Now I have another problem: I managed to realize a command that generates a rectangular spiral, and when the launch for the first time works perfectly, but the next launches generates a crippled spiral. it seems that there is some variable that I use that is not initialized; at the beginning of the command I placed all variables equal to 0 but the situation does not change
 
OK here is the code:
(defun c:spirett ()

(Sectq x1 0);
(seq y1 0) ;
(Sectq x2 0);
(seq y2 0) ;;
(Sectq x3 0);
(seq y3 0) ;
(Sectq x4 0);
(seq y4 0) ;
(Sectq x5 0);
(seq y5 0) ;;
(Sectq x6 0);
(seq y6 0) ;;
(setq d1 0); variable initialization
(seq d2 0) ;
(Sect. 0) ;;
(Sectq kmax 0);
(setq nmax 0);
(Sectq k 0) ;
(Sect No 0);
(Sectq cl 0);
(Sectq ps 0);
(Sect to 0);
(Sectq r 0);
(Sects 0) ;

(Sectq d1) ;
(setq d2 (getdist "height:"));; impt data for construction
(seq step (getreal "specify step:");
(setq ps (getpoint "specify starting point:"));




(setq kmax (min d1 d2);

(command "_pline");
(list step by step) ;;
(list(* 2 step) step;
(list(* 2 step) 0;
(list(* 3 step) 0); creates closing edges
(list (* 3 step) (* 2 step));
(list 0 (* 2 step));
(list 0 0 0)
;
(Sectq cl (entlast) ;;



(Sectq p1 ps) ;;
(Sectq x1 (car p1));
(Sectq y1 (cadr p1));
(setq x2 (+ d1 x1)) ;; coordinates of the points of the external mandate coil
(setq y2 (+ d2 y1) ;;
(setq x3 (+ x1(* 2 step)));
(setq y3 (+ y1 (* 2 step)));

(setq p1 (list x1 y1) ;;
(setq p2 (list x1 y2);
(setq p3 (list x2 y2);; external spire points
(setq p4 (list x2 y1) ;;
(setq p5 (list x3 y1) ;;
(setq p6 (list x3 y3);

(setq pf p3) ;; final point for the selection rectangle

(command "_pline" p1 p2 p3 p4 p5 p6");
(setq a (entlast)

(setq x1 x3);
(seq y1 y3);
(Sectq x2 (- x2 (* 2 step));
(setq y2 (- y2 (* 2 step)));
(setq x3 (+ x3(* 2 step)));
(setq y3 (+ y3)));

(setq k (* 4 step));

(while;); ;
(- kmax k) (* 4 step) ;;
(setq p1 (list x1 y1) ;;
(setq p2 (list x1 y2);
(setq p3 (list x2 y2);
(setq p4 (list x2 y1) ;;
(setq p5 (list x3 y1) ;;
(setq p6 (list x3 y3);
;;
(command "_pline" p1 p2 p3 p4 p5 p6");; it executes coils until there is space
;;
(setq x1 x3);
(seq y1 y3);
(Sectq x2 (- x2 (* 2 step));
(setq y2 (- y2 (* 2 step));
(setq x3 (+ x3(* 2 step)));
(setq y3 (+ y3)));
(setq k (+ k)) ;;
)


(setq sset (ssget "_c" ps pf));; it unites the created edges using as a base
(command "_join" to sset")



;; performs the same procedure for return with an offset equal to the step

(setq nmax (- kmax (* 2 step)))
(setq d3 (- d1 (* 2 step)))
(setq d4 (- d2 (* 2 step)))


(setq x7 (+ (car ps) step))
(setq y7 (+ (cadr ps) step))
(setq x8 (+ d3 x7))
(setq y8 (+ d4 y7))
(setq x9 (+ x7 (* 2 step))))
(setq y9 (+ y7 (* 2 step)))

(setq p7 (list x7 y7))
(setq p8 (list x7 y8))
(setq p9 (list x8 y8))
(setq p10 (list x8 y7))
(setq p11 (list x9 y7))
(setq p12 (list x9 y9)

(command "_pline" p7 p9 p10 p11 p12 ")
(setq r (entlast)

(setq x7 x9)
(setq y7 y9)
(setq x8 (- x8 (* 2 step)))
(setq y8 (- y8 (* 2 step)))
(setq x9 (+ x9 (* 2 step))))
(setq y9 (+ y9 (* 2 step))))
(setq n (* 4 step))

(sing)
(* 4 step)
(setq p7 (list x7 y7))
(setq p8 (list x7 y8))
(setq p9 (list x8 y8))
(setq p10 (list x8 y7))
(setq p11 (list x9 y7))
(setq p12 (list x9 y9)

(command "_pline" p7 p9 p10 p11 p12 ")

(setq x7 x9)
(setq y7 y9)
(setq x8 (- x8 (* 2 step)))
(setq y8 (- y8 (* 2 step)))
(setq x9 (+ x9 (* 2 step))))
(setq y9 (+ y9 (* 2 step))))
(setq n (+ n* 4 step)))
)

(setq sset (ssget "_c" ps pf))
(command "_join" r sset")



(if (> x1 x7);
(command "_move" cl "0,0" p12);;
(command "_move" cl "0,0" p6);; place the closing edge
;
(command "_join" cl r");


)

I apologize in advance for my raw moooooooooolto programming:) I am unfortunately self-taught
 
apart from the fact that the program did not give me boredom even to the second sending, you probably have to have some osnap inserted. I limited myself to adding the set to 0 of the osnap and at the end of the command the return to the original condition before the command. the initialized variables have no value therefore it was written (setq variable nil), in fact 0 is a value different from nil. to make the way that the variables return "empty" i.e. to nil, you must insert them between the brackets at the beginning of the command, to understand the first after the deceased preceded by a sign / -> (/ x1 y1 x2 ...). However it is all in the attached file.
 

Attachments

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
ciao
Back
Top