×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Nearest point in AutoCAD

Nearest point in AutoCAD

Nearest point in AutoCAD

(OP)
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

RE: Nearest point in AutoCAD

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

RE: Nearest point in AutoCAD

(OP)
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 :(

RE: Nearest point in AutoCAD

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.

RE: Nearest point in AutoCAD

(OP)
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 :)

RE: Nearest point in AutoCAD

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 www.tek-tips.com are great for getting quick and effective help.

RE: Nearest point in AutoCAD

(OP)
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.

RE: Nearest point in AutoCAD

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.

RE: Nearest point in AutoCAD

(OP)
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# :)

RE: Nearest point in AutoCAD

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?

RE: Nearest point in AutoCAD

(OP)
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 :(

RE: Nearest point in AutoCAD

Do you need to zoom in first, find your line, then zoom out?

RE: Nearest point in AutoCAD

(OP)
That would solve this problem, but I don't like much this zoom approach, taht's why I decided for the numerical methods.

RE: Nearest point in AutoCAD

You can freeze the screen, then zoom, pick and zoom previous so the observer is not aware and regens are avoided.

RE: Nearest point in AutoCAD

(OP)
That would be a very nice alternative!!! :)

Haven't thought of that! Thanks! :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources