Measure between Origin and a component plane

Measure between Origin and a component plane

6.Day.Old.Filet-O-Fish
Enthusiast Enthusiast
122 Views
2 Replies
Message 1 of 3

Measure between Origin and a component plane

6.Day.Old.Filet-O-Fish
Enthusiast
Enthusiast

I have an assembly and I need to measure the distance between its YZ plane and a plane within a component.

 

I'm having issues with a bit of code. It is not throwing any errors but is getting the wrong solution. It always equals 0mm even though the actual measurement is several meters. What am I doing wrong?

' Get the assembly document
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Get the assembly YZ plane
Dim asmYZPlane As WorkPlane = asmDoc.ComponentDefinition.WorkPlanes.Item("YZ Plane")

' Get the component occurrence
Dim compOcc As ComponentOccurrence = asmDoc.ComponentDefinition.Occurrences.ItemByName("Component1")

' Get the work plane from the component
Dim planeB As WorkPlane = compOcc.Definition.WorkPlanes.Item("Component1_Plane")

' Use MeasureTools to get the minimum distance
Dim measureTools As MeasureTools = ThisApplication.MeasureTools
Dim distance As Double = measureTools.GetMinimumDistance(asmYZPlane.Plane, planeB.Plane)

' Convert distance from cm to mm (if needed)
distance = distance * 10
' Output the result
MessageBox.Show("Distance between YZ Plane and PADEYE_REAR of PADEYE: " & distance & " mm")

 

0 Likes
Accepted solutions (1)
123 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Looks like you are just missing the step where you need to get the 'proxy' of that component's WorkPlane that is in the context of the assembly, instead of in the context of that component's definition.  See altered example below.  Then, use the faces, or WorkPlane objects directly, instead of their 'planes'.

' Get the assembly document
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Get the assembly YZ plane
Dim asmYZPlane As WorkPlane = asmDoc.ComponentDefinition.WorkPlanes.Item("YZ Plane")

' Get the component occurrence
Dim compOcc As ComponentOccurrence = asmDoc.ComponentDefinition.Occurrences.ItemByName("Component1")

' Get the work plane from the component
Dim planeB As WorkPlane = compOcc.Definition.WorkPlanes.Item("Component1_Plane")

'get the 'proxy' of that component's WorkPlane that is in the context of the assembly
'first create the variable for the proxy
Dim planeBProxy As WorkPlaneProxy = Nothing
'now use a method of the component to get the proxy, supplying both variables
'this sets the value of the proxy variable
compOcc.CreateGeometryProxy(planeB, planeBProxy)

'now use that proxy object for the measurement, instead of the original

' Use MeasureTools to get the minimum distance
Dim measureTools As MeasureTools = ThisApplication.MeasureTools
Dim distance As Double = measureTools.GetMinimumDistance(asmYZPlane, planeBProxy)

' Convert distance from cm to mm (if needed)
distance = distance * 10
' Output the result
MessageBox.Show("Distance between YZ Plane and PADEYE_REAR of PADEYE: " & distance & " mm")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

6.Day.Old.Filet-O-Fish
Enthusiast
Enthusiast

TY kind sir! So fast, prolly cause it was obvious!
I gotta learn that 'proxy' stuff. Still doesn't make sense to me but not the first time it's hung me up.

0 Likes