Comparing vlax-curve-getStartPoint and vlax-curve-getEndPoint of open polylines

Comparing vlax-curve-getStartPoint and vlax-curve-getEndPoint of open polylines

Anonymous
Not applicable
1,391 Views
3 Replies
Message 1 of 4

Comparing vlax-curve-getStartPoint and vlax-curve-getEndPoint of open polylines

Anonymous
Not applicable

Hello!

I would like to compare the first and last coordinates of a polyline and then close it when the results were equals

 

This code does not work, the IF line never returns TRUE

 

(setq ename (entsel "Select object to be closed"))
(setq obj (vlax-ename->vla-object (car ename)) )
(setq StartPoint (vlax-curve-getStartPoint Obj) )
(setq EndPoint (vlax-curve-getEndPoint Obj) )
(if (= (strcat StartPoint) (strcat EndPoint))
     (vlax-put-property obj 'Closed 1)
)

 

What am I doing wrong?

 

Thanks in advance + regards,

lzucco

0 Likes
Accepted solutions (2)
1,392 Views
3 Replies
Replies (3)
Message 2 of 4

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

Try another way like.....

 

(if (= (distance StartPoint EndPoint) 0.0)
     (vlax-put-property obj 'Closed 1)
)

 

or 

 

(if (equal StartPoint EndPoint)
     (vlax-put-property obj 'Closed 1)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 3 of 4

Kent1Cooper
Consultant
Consultant

Be aware of two things:

 

Those solutions have the possibility of failing with way-down-at-the-14th-or-so-decimal-place variations in coordinate values that those start and end vertices may have.  I would suggest the one using (equal) but with a small fuzz factor added.

 

BUT  what they will do is to close the Polyline by adding a zero-length segment from the last vertex to the first  [which are at the same place].  If it's a rectangle, it will still have 5 vertices, not the 4 that one made with the RECTANG command would have, or if drawn manually using the Close option after the 4th vertex.  Coincident vertices like that can cause certain problems if you process the Polyline with other routines.  If you want to close one like that in a way that eliminates the coincident vertices, you can use PLCloseCorner.lsp, available >here<.  Read more on that thread for further discussion of the issue.

Kent Cooper, AIA
Message 4 of 4

dlanorh
Advisor
Advisor
Accepted solution

A bit late to this, but this snippet will check and close where neccessary.

 

(setq obj (vlax-ename->vla-object (car (entsel "\nSelect Polyline Object ")))
      fuzz 1.0e-6
)
(if (and (equal (vlax-curve-getstartpoint obj) (vlax-curve-getendpoint obj) fuzz)
         (equal :vlax-false (vlax-get-property obj 'closed))
    )         
    (vlax-put-property obj 'closed :vlax-true)
)

I am not one of the robots you're looking for