Get start and end point of lines

Get start and end point of lines

etilley327KA
Advocate Advocate
3,093 Views
5 Replies
Message 1 of 6

Get start and end point of lines

etilley327KA
Advocate
Advocate

Im trying to figure out how to get the start and end point of two different lines so I can pass it to the align command. How might I go about that? Thanks

 

(defun c:tyty ()

       (setq Sline (entsel "\nSelect Source property line: "))
       (command "_.flatten" Sline "" "")
       (setq Sline (car Sline))
       (setq Dline (car (nentsel "\nSelect Destination property line: ")))
       (setq
          1stS (vlax-curve-getStartPoint Sline)
          2ndS (vlax-curve-getEndPoint Sline))
       (setq
          1ndD (vlax-curve-getStartPoint Dline)
          2ndD (vlax-curve-getEndPoint Dline))

(print 1stS)
(print 2stS)
(print 1stD)
(print 2stD)
)
0 Likes
Accepted solutions (1)
3,094 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor

@etilley327KA  hi,

 

using classic autolisp, check this code

 

(defun c:test (/ pick ename elist p1 p2)

 (if (and
       (setq pick (entsel "\npick line: "))
       (setq ename (car pick))
       (setq elist (entget ename))
       (eq (cdr (assoc '0 elist)) "LINE")
     )
  (progn
   (setq p1 (cdr (assoc '10 elist)) p2 (cdr (assoc '11 elist)))
   (princ (list p1 p2))
  ); progn
 ); if


 (princ)
)

 

 

 

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

You have bolluxed up variable names.  If you change 1ndD to 1stD, and 2stS to 2ndS, and 2stD to 2ndD, does it do what you want?

 

EDIT:  Also, FLATTEN is [as of Acad2020 that I have here] an Express Tool, not a native AutoCAD command, so it can't be used in a (command) function.  Comment out that part and see whether the variable name correction gets you what you want [it does for me, reporting four sets of point coordinates].

And, by "property line" do you mean a LINE object specifically, or might it be something else?  Your (vlax-curve-...) functions could get the ends from Lines or Polylines or even Arcs, but the code in Message 2 will work only with LINE objects.  But another possible complication -- if Polylines, are you looking for the ends of a segment within a longer one, such as one edge of a property boundary could be?

Kent Cooper, AIA
0 Likes
Message 4 of 6

etilley327KA
Advocate
Advocate
Yes, its just a line. So how would I go about setting the Z of the line to zero?
0 Likes
Message 5 of 6

etilley327KA
Advocate
Advocate

Nevermind, I think I figured it out.

 

(command"_.CHANGE" Sline "" "_P" "_E" "0" "")
0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

Nevermind, I think I figured it out.

(command"_.CHANGE" Sline "" "_P" "_E" "0" "")


It won't let you do that if the Z coordinates at the ends of the Line differ:

Cannot change elevation of objects with differing Z coordinates.

But if it's in a plane parallel to the WCS XY plane, i.e. its endpoints have equal but non-zero Z coordinates, you can put it where you want it that way.

Kent Cooper, AIA
0 Likes