WereWolf Posted March 9, 2016 Posted March 9, 2016 Hello, I am new in coding lisp files. I worked with vb.net so this is very strange for me at this moment . I want to to select two points with different coordinates and to calculate difference between Z. I want to label that difference and to draw line with specific length under text. I did some coding which I pasted below but it wont draw line. I think that somehow I can not create pt2 and use it. Please help me because my head will blow... Code is below... THANKS (defun c:raz ( / p textloc p1 p2) (vl-load-com) (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq p (getpoint "Odaberite tacku terena: ")) (setq zt (rtos (caddr p))) (setq pomocni 1) (setq p5 (getpoint "Odaberite tacku toplovoda: ")) (setq zc (rtos (caddr p5))) (setq p1 (getpoint "\nOdaberi poziciju teksta.")) (setq y (rtos (car p1))) (setq x (rtos (cadr p1))) (setq z (rtos (caddr p1))) (setq thetext (vla-AddText mspace zt (vlax-3d-point (car p1) (cadr p1) [lz] ) "0.65")) (setq TTT (atof(cadr p1))) (setq p2 (list (+ TTT 2.24) (cadr p1) (caddr p1))) (setq YY (- x pomocni)) (command "Line" p1 p2 "") ) Quote
Hippe013 Posted March 9, 2016 Posted March 9, 2016 Try the following: (setq line_obj (vlax-invoke-method mspace 'AddLine (vlax-3d-point p1)(vlax-3d-point p2))) Quote
Hippe013 Posted March 9, 2016 Posted March 9, 2016 Also... (setq TTT (atof (cadr p1))) This line fails because atof needs to be supplied with a string. Quote
Hippe013 Posted March 9, 2016 Posted March 9, 2016 Further more... (setq YY (- x pomocni)) This line fails because the variable x is a string. Try: (setq yy (- (read x) pomocni)) Quote
WereWolf Posted March 9, 2016 Author Posted March 9, 2016 I know that there is error in the line where I set TTT. Can you please explain me what format is car p1? Is it real number or string or something else? I always get this error message: error: bad argument type: stringp 2026.12 And 2026.12 is x coordinate of p1. So TTT is not correct type.... Quote
Hippe013 Posted March 9, 2016 Posted March 9, 2016 P = (1 2 3) Car p = 1 Cadr p = 2 Caddr p = 3 Nth 0 p = 1 Nth 1 p = 2 Nth 2 p = 3 All real numbers. Quote
WereWolf Posted March 10, 2016 Author Posted March 10, 2016 Can somebody please help me with this problem. I am stuck with it... Quote
BKT Posted March 10, 2016 Posted March 10, 2016 Give these changes a try. As Hippe013 pointed out, you have to watch for strings versus numbers. (defun c:raz ( / p textloc thetext p1 p2) (vl-load-com) (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq p (getpoint "Odaberite tacku terena: ")) (setq zt (rtos (caddr p) 2 3)) (setq pomocni 1) (setq p5 (getpoint "Odaberite tacku toplovoda: ")) (setq zc (rtos (abs (caddr p5)) 2 3)) (setq p1 (getpoint "\nOdaberi poziciju teksta.")) (setq x (car p1)) (setq y (cadr p1)) (setq z (caddr p1)) (setq thetext (vla-AddText mspace zt (vlax-3d-point (car p1) (cadr p1) (caddr p1) ) "0.65")) (setq TTT (car p1)) (setq p2 (list (+ TTT 2.24) (cadr p1) (caddr p1))) (setq YY (- x pomocni)) (command "Line" p1 p2 "") ) Quote
WereWolf Posted March 10, 2016 Author Posted March 10, 2016 I have tried that already... Iget this type of error: error: bad argument type: numberp: "1547.0728" where 1547.0728 is x coordinate of p1... I can not figure where I am wrong... Quote
BKT Posted March 10, 2016 Posted March 10, 2016 Did you use the code I posted or did you change your original code? Quote
WereWolf Posted March 10, 2016 Author Posted March 10, 2016 WOW... I did not look whole code but just part I thought it was bad... Thank you so so so much... That work very good... Thank you again... Quote
BKT Posted March 10, 2016 Posted March 10, 2016 You're very welcome. I'm glad it works for you! Quote
WereWolf Posted March 10, 2016 Author Posted March 10, 2016 Please can u explain what was my mistake? I see in code where you changed but is it too much to ask for explanation? Quote
BKT Posted March 10, 2016 Posted March 10, 2016 Here are the changes I made. I'll highlight them in red: (defun c:raz ( / p textloc p1 p2) (vl-load-com) (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq p (getpoint "Odaberite tacku terena: ")) (setq zt (rtos (caddr p))[color=red]);; (rtos (caddr p) 2 3) limits digits to 3[/color] (setq pomocni 1) (setq p5 (getpoint "Odaberite tacku toplovoda: ")) (setq zc (rtos (caddr p5)))[color=red];; (rtos (abs (caddr p5)) 2 3) abs forces to absolute value[/color] (setq p1 (getpoint "\nOdaberi poziciju teksta.")) (setq y (rtos (car p1)))[color=red];; changed "y" to "x" and removed rtos (keeps it a number)[/color] (setq x (rtos (cadr p1)))[color=red];; changed "x" to "y" and removed rtos (keeps it a number)[/color] (setq z (rtos (caddr p1)))[color=red];; removed rtos (keeps it a number)[/color] (setq thetext (vla-AddText mspace zt (vlax-3d-point (car p1) (cadr p1) [lz] ) "0.65"))[color=red];; changed this to (caddr p1) [/color] (setq TTT (atof(cadr p1)))[color=red];; changed to "x" value of p1 and removed atof[/color] (setq p2 (list (+ TTT 2.24) (cadr p1) (caddr p1))) (setq YY (- x pomocni)) (command "Line" p1 p2 "") ) Hope I didn't mess up your requirements by my changes! Quote
WereWolf Posted March 10, 2016 Author Posted March 10, 2016 Thank you very much.. I labeled car p1 as y as I am survey engineer and we use Y as primary axis... Thank you once again... Quote
BKT Posted March 10, 2016 Posted March 10, 2016 Thank you very much.. I labeled car p1 as y as I am survey engineer and we use Y as primary axis... Thank you once again... Ah... makes sense. I'm glad I could help you! Quote
Recommended Posts
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.