Vector of minimum distance

<?xml encoding=”UTF-8″>By Adam Nagy

There is a utility object in the API called MeasureTools that enables you to do the same measuring that is available in the UI: e.g. to get the minimum distance between components of an assembly. In the UI you can also see a line showing the distance between the components:

Mindist_UI 

You can get back the points of the distance line and the objects it was measured between using the API as well. Here is the description in the API Help file about the last parameter of GetMinimumDistance:

Context – Optional output NameValueMap object that returns additional information regarding the measurement. Following are the possible return values (descriptions are below the table):

ClosestPointOnePoint object that returns a transient point closest to entity one in the minimum distance measure. This point may or may not lie on entity one (but will lie on the plane or axis of entity one). If entity one is a position input (Point, Vertex, WorkPoint, etc.), the position of the input entity is returned

ClosestPointTwoPoint object that returns a transient point closest to entity two in the minimum distance measure. This point may or may not lie on entity two (but will lie on the plane or axis of entity two). If entity two is a position input (Point, Vertex, WorkPoint, etc.), the position of the input entity is returned

ClosestEntityOneObject type that returns the entity on which the returned ClosestPointOne lies. This is applicable only in the case where the input EntityOne is a ComponentOccurrence (or its proxy)

ClosestEntityTwoObject type that returns the entity on which the returned ClosestPointTwo lies. This is applicable only in the case where the input EntityTwo is a ComponentOccurrence (or its proxy)

IntersectionFoundBoolean that indicates whether an intersection was found between entities one and two. If True, the method returns a value of 0

The below VBA code will create two work points to represent the points we get from the GetMinimumDistance function:

Sub MinDistance()
Dim doc As AssemblyDocument
Set doc = ThisApplication.ActiveDocument
Dim occs As ComponentOccurrences
Set occs = doc.ComponentDefinition.Occurrences
Dim context As NameValueMap
Dim dist As Double
dist = ThisApplication.MeasureTools.GetMinimumDistance( _
occs(1), occs(2), , , context)
' Let's add the points as work points
Dim wps As WorkPoints
Set wps = doc.ComponentDefinition.WorkPoints
Call wps.AddFixed(context.Item("ClosestPointOne"))
Call wps.AddFixed(context.Item("ClosestPointTwo"))
End Sub

And here is the result of the above code:

Mindist_API

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading