error: bad argument type: 2D/3D point: nil

error: bad argument type: 2D/3D point: nil

Anonymous
Not applicable
2,683 Views
6 Replies
Message 1 of 7

error: bad argument type: 2D/3D point: nil

Anonymous
Not applicable

I'm trying to get the distance until a certain point but keep getting the same error. The point exist in the line.

 

this is my code:

 


(setq Ent (entsel "Select the polyline : " ) )

 

(setq Vl-Obj (vlax-ename->vla-Object (car Ent )) )

 

(setq p2 (list -102469.3 -47412.9 0.0)

 

(vlax-curve-getDistAtPoint vl-obj pt2)

0 Likes
Accepted solutions (1)
2,684 Views
6 Replies
Replies (6)
Message 2 of 7

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

I'm trying to get the distance until a certain point but keep getting the same error. The point exist in the line.

 

.............

 

(setq p2 (list -102469.3 -47412.9 0.0)

 

(vlax-curve-getDistAtPoint vl-obj pt2)


You are calling the wrong variable pt2. It should be p2.

Message 3 of 7

Anonymous
Not applicable

I fixed that, but now i'm getting nil as answer

0 Likes
Message 4 of 7

Ranjit_Singh
Advisor
Advisor
Accepted solution

You cannot exactly catch a point on the polyline by typing it in because of decimal issue. Try this

(vlax-curve-getDistAtPoint vl-obj (vlax-curve-getclosestpointto vl-obj p2))
0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

[The (vlax-curve...) functions will take entity names -- no need to convert to a VLA object unless you need that for some other purpose.]

[You're also missing the closing  )  on the (setq p2... line.]

 

Another way to go about getting the point exactly on it from the point that apparently isn't quite on it:

 

(setq Ent (entsel "Select the polyline : "))

 

(setq p2 (list -102469.3 -47412.9 0.0))

 

(vlax-curve-getDistAtPoint (car ent) (osnap p2 "nea"))

Kent Cooper, AIA
0 Likes
Message 6 of 7

john.uhden
Mentor
Mentor

@Kent1Cooper wrote, "(vlax-curve-getDistAtPoint (car ent) (osnap p2 "nea"))"

 

That's fine if there are no other nearby objects.

I think that closestpointto is more reliable because it focuses on the object of interest.

I presume that precision makes a difference in the "atpoint" functions, though I have not done a study.

That's why we should write code that covers the misses without erroring out...

 

(or
  (setq p (vlax-curve-getclosestpointto object p))
  (prompt "\nUnable to find closest point to object.")
)

John F. Uhden

Message 7 of 7

Anonymous
Not applicable

Your explanation made a lot of sense ! Thank you so much for the help ! 

It worked just fine ! 

0 Likes