Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nearest point in AutoCAD

Status
Not open for further replies.

RBasniak

Mechanical
Sep 19, 2001
59
0
0
BR
Hi people...

Does anyone knows how could I get the nearest point of an entity of the point I inform?

Let's say I have a spline and in a top view I know one point (X and Y) which is really near it, and I need to know the Z coordinate of the spline there. I have a large experience in VBA with SolidWorks, Excel, etc... But completely new to AutoCAD VBA, I tried to found any method to simulate the Nearest Osnap, but could find. Any idea?

Best Regards,
Rodrigo Basniak
 
Replies continue below

Recommended for you

not sure but i would think that you would have to loop through the coordinates of Acad3dPolyline to find the one that meets your condition

I haven't done any acadvba in awhile..proe as of late..but i remember the 3d poly being a ugly variant ..used it to drive cnc code
 
Hi,

The problem is that the coordinates I want are betwen the poins of Acad3dPolyline. :( I'm pretty sad that AutoCAD doesn't let you access this kind of data :(

I resolved the problem, but in a much longer way:

With the points of Acad3dPolyline I used polynomial interpolation and found the spline's equation... with the equation is easy to get any point on the spline. Too bad each spline has at least 100 points, so to find this equation I have to solve linear systems with around 100 equations each :(
 
Can you just ask Vb to get the ID of a point NEArest to the coordinates you pass to the function? Of course, the aperture box has to be large enough to contain the spline object. It's like using (setq pt (getpoint NEA "10,20")) in an Autocad macro.
 
I tried that too, but the grid of splines is too dense to the NEA osnap work properly, that's why I used the numerical methods and did it independent of autocad tools :)
 
Have you considered programming in Visual Basic. I have primarily worked in VBA but have recently started using VB. I have found that VBA is extremely slow when a large number of caclulations are done, VB is faster partly because it does not rely on the application to compile and run the code.

You already have done the math, you just need to transfer the information from AutoCAD to VB for processing.

There is a learning curve but this site and are great for getting quick and effective help.
 
VB would be a better alternative for sure, it's faster and a lot more flexible, but the company I work at don't have any copy of VB, so I have to work with VBA, but even with all those calculations the code is not as slow as I thought it would be... :) Since it's not an application you'll run dozens of times in a day, it's acceptable.
 
Good points. If however you have no life Microsoft is giving away copies of Visual Basic for personal at home use. Its not a bad deal if you are interested learning other programming languages, C# is also available.

You could develop programs at home to improve your productivity at work.
 
I've worked with VB for a while, but learn a little bit of C# wouldn't hurt :) Thanks for the tip, I'll see if I can get one copy of C# :)
 
I don't know VBA, but in visual lisp/VLA there are 2 functions that would make your job easier; "vlax-curve-getClosestPointTo" and "vlax-curve-getClosestPointToProjection". Can you access these through VBA?
 
Nope... The closest I can get from these function with VBA is emulating the NEAREST osnap, but my splines are too much close from each other that this doesn't work properly :(
 
Status
Not open for further replies.
Back
Top