Pline p1 p2

Pline p1 p2

cadtesthelp
Explorer Explorer
822 Views
6 Replies
Message 1 of 7

Pline p1 p2

cadtesthelp
Explorer
Explorer

Greetings.

First of all, I want to thank everyone who contributes to this forum!

 

I am a beginner in the world of AutoLISP and I am stuck in a list routine.

A portion of a LISP that I am creating is not functioning as I intended.

I have isolated the problematic portion and would appreciate some assistance in fixing it.

 

The portion in question is as follows:

I am attempting to create a polyline with its endpoint at a distance of 80mm less than the distance between two specified points.

 

I understand that I may be overlooking something very basic, but as I mentioned, I am still in the process of learning.

Could someone kindly point out what might be wrong here?

 

 

(defun c:l1 ()

  (setq p1 (getpoint "\nInsert first point...")
        p2 (getpoint "\nInsert second point..."))  
  (setq dist1 (rtos (- (distance p1 p2) 80)))
  (setq dist2 (strcat "@"dist1"<0"))
  
  (command "_pline" p1 dist2 "")

  (princ)
)

 

 
cadtesthelp_1-1709420426799.png
 
Thank you for your help!
0 Likes
Accepted solutions (2)
823 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor

It is much easier to use the polar function, (setq pt3 (polar pt1 angle distance)). Leave distance as a real, pline pt1 pt3. Note angle is in radians for polar function.

 

You have 2 points so can work out an angle if you want or ignore if want horizontal ang = 0.0. 

 

 

 

       p2 (getpoint pt1 "\nInsert second point..."))  ; will show rubber band from pt1

 

 

0 Likes
Message 3 of 7

cadtesthelp
Explorer
Explorer

Thanks a bunch for your reply!

I tried looking into the polar function as you mentioned, but I'm afraid I got a bit lost trying to fit it into my code. As a beginner, I'm still getting the hang of things.

 

0 Likes
Message 4 of 7

paullimapa
Mentor
Mentor
Accepted solution

try these modifications which would allow it to work based on current drawing units and different angles:

(defun c:l1 (/ p1 p2 dist1 ang dist2) ; localize variables
 (if
  (setq p1 (getpoint "\nInsert first point...")
        p2 (getpoint p1 "\nInsert second point...")
     dist1 (rtos (- (distance p1 p2) 80) (getvar "LUNITS") 4) ; convert real to string based on current unit setting
       ang (angtos (angle p1 p2) 0 4) ; get angle between two points and convert to string using decimal degree units
     dist2 (strcat "@" dist1 "<" ang) ; string variables together
  )
  ; execute command only when all variables set
  (command "_.Pline" "_None" p1 "_None" dist2 "")
 )
(princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 7

cadtesthelp
Explorer
Explorer

Thank you very much!

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

This trick of using screen-relative polar input

@Anonymous<ang 

is rarely used in programming. The reason is mainly the loss of precision when converting to strings.

 

There are several methods to program it like this, probably the simplest is to use the polar function mentioned above.

 

(defun c:l1 ( / p1 p2 dst ang p3)

  (setq p1 (getpoint "\nSpecify first point: "))
  (setq p2 (getpoint p1 "\nSpecify second point: "))
  (setq dst (distance p1 p2))

  (if (> dst 80)
    (progn
      (setq ang (angle p1 p2))
      (setq p3 (polar p1 ang (- dst 80)))
      (command "_pline" "_non" p1 "_non" p3 "") ; _non turns off osnaps, very important!
      )
    (princ "Error: Specified points are too close to each other!"))
  (princ)
)

 

0 Likes
Message 7 of 7

paullimapa
Mentor
Mentor

Glad to have helped…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes