Jump to content

Need help with LISP please


WereWolf

Recommended Posts

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 "")

)

Link to comment
Share on other sites

Try the following:

 

(setq line_obj (vlax-invoke-method mspace 'AddLine (vlax-3d-point p1)(vlax-3d-point p2)))

Link to comment
Share on other sites

Further more...

 

(setq YY (- x pomocni))

 

This line fails because the variable x is a string.

 

Try:

 

(setq yy (- (read x) pomocni))

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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 "")

)

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!

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...