Nearest point in AutoCAD VBA
Nearest point in AutoCAD VBA
(OP)
Hi people...
Does anyone knows how could I get the nearest point of an entity of the point I inform using VBA?
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
Does anyone knows how could I get the nearest point of an entity of the point I inform using VBA?
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 VBA
"Everybody is ignorant, only on different subjects." — Will Rogers
RE: Nearest point in AutoCAD VBA
No... the closest distance is zero, but for some reasons autocad is not recognizing this as a intersection. So I'm trying to find out the Z coordinate of a point that lies on a 3d spline given the X and Y coordinates.
Thanks,
Rodrigo Basniak
RE: Nearest point in AutoCAD VBA
"Everybody is ignorant, only on different subjects." — Will Rogers
RE: Nearest point in AutoCAD VBA
RE: Nearest point in AutoCAD VBA
"Everybody is ignorant, only on different subjects." — Will Rogers
RE: Nearest point in AutoCAD VBA
RE: Nearest point in AutoCAD VBA
In manual AutoCAD, trimming the spline, then id-ing the endpoint works, FWIW.
RE: Nearest point in AutoCAD VBA
RE: Nearest point in AutoCAD VBA
"Everybody is ignorant, only on different subjects." — Will Rogers
RE: Nearest point in AutoCAD VBA
RE: Nearest point in AutoCAD VBA
Sub Example_IntersectWith()
Dim splineObj As AcadSpline
Dim startTan(0 To 2) As Double
Dim endTan(0 To 2) As Double
Dim fitPoints(0 To 8) As Double
startTan(0) = 0.5: startTan(1) = 0.5: startTan(2) = 0
endTan(0) = 0.5: endTan(1) = 0.5: endTan(2) = 0
fitPoints(0) = 1: fitPoints(1) = 1: fitPoints(2) = 0
fitPoints(3) = 5: fitPoints(4) = 5: fitPoints(5) = 0
fitPoints(6) = 10: fitPoints(7) = 0: fitPoints(8) = 0
Set splineObj = ThisDrawing.ModelSpace.AddSpline(fitPoints, startTan, endTan)
Dim lineObj As AcadLine
Dim startPt(0 To 2) As Double
Dim endPt(0 To 2) As Double
startPt(0) = 1: startPt(1) = 1: startPt(2) = 0
endPt(0) = 5: endPt(1) = 5: endPt(2) = 0
Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
ZoomAll
' Find the intersection points between the line and the circle
Dim intPoints As Variant
intPoints = lineObj.IntersectWith(splineObj, acExtendThisEntity)
' Print all the intersection points
Dim I As Integer, j As Integer, k As Integer
Dim str As String
If VarType(intPoints) <> vbEmpty Then
For I = LBound(intPoints) To UBound(intPoints)
str = "Intersection Point[" & k & "] is: " & intPoints(j) & "," & intPoints(j + 1) & "," & intPoints(j + 2)
MsgBox str, , "IntersectWith Example"
str = ""
I = I + 2
j = j + 3
k = k + 1
Next
End If
End Sub
"Everybody is ignorant, only on different subjects." — Will Rogers