Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

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

Anonymous

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
Reply
Accepted solutions (1)
2,497 Views
6 Replies
Replies (6)

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

Anonymous
Not applicable

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

0 Likes

Ranjit_Singh2
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

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

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

Anonymous
Not applicable

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

It worked just fine ! 

0 Likes