Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
2475 Views, 6 Replies

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

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)

6 REPLIES 6
Message 2 of 7
Ranjit_Singh2
in reply to: Anonymous


@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
in reply to: Ranjit_Singh2

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

Message 4 of 7
Ranjit_Singh2
in reply to: Anonymous

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))
Message 5 of 7
Kent1Cooper
in reply to: Anonymous

[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
Message 6 of 7
john.uhden
in reply to: Kent1Cooper

@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
in reply to: Ranjit_Singh2

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

It worked just fine ! 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report