Is there a way to find the x,y,z, position of an parts center point in an assembly?

Is there a way to find the x,y,z, position of an parts center point in an assembly?

chris
Advisor Advisor
639 Views
7 Replies
Message 1 of 8

Is there a way to find the x,y,z, position of an parts center point in an assembly?

chris
Advisor
Advisor

I am wondering if there is an easy way to find the x,y,z, position of a parts center point within an assembly? what would be great is if I could select a part and run a rule that would give my the offsets from the assemblies center.

0 Likes
Accepted solutions (1)
640 Views
7 Replies
Replies (7)
Message 2 of 8

Andrii_Humeniuk
Advisor
Advisor

Hi @chris . This iLogic code measures the distance between the centers of the assembly and part along the x, y, z axes in millimeters.

Dim oInvApp As Inventor.Application = ThisApplication
Dim oMT As MeasureTools = oInvApp.MeasureTools
Dim oADoc As AssemblyDocument = TryCast(oInvApp.ActiveDocument, AssemblyDocument)
If oADoc Is Nothing Then Exit Sub
Dim oWrkPlanes As WorkPlanes = oADoc.ComponentDefinition.WorkPlanes
Dim oOcc As ComponentOccurrence
oOcc = oInvApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part...")
If oOcc Is Nothing Then Exit Sub
Dim oPoint As WorkPoint = oOcc.Definition.WorkPoints(1)
Dim oPrxPoint As WorkPointProxy : Call oOcc.CreateGeometryProxy(oPoint, oPrxPoint)
Dim dX As Double = Round(oMT.GetMinimumDistance(oWrkPlanes(1), oPrxPoint), 3) ' YZ Plane
Dim dY As Double = Round(oMT.GetMinimumDistance(oWrkPlanes(2), oPrxPoint), 3) ' XZ Plane
Dim dZ As Double = Round(oMT.GetMinimumDistance(oWrkPlanes(3), oPrxPoint), 3) ' XY Plane
MessageBox.Show("X - " & dX * 10 & " mm" & vbLf &
				"Y - " & dY * 10 & " mm" & vbLf &
				"Z - " & dZ * 10 & " mm", oOcc.Name)

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 8

chris
Advisor
Advisor

@Andrii_Humeniuk This works great, thank you! what would I need to change to get the returned values in "inches"?

0 Likes
Message 4 of 8

Andrii_Humeniuk
Advisor
Advisor

You can convert units of measure using the UnitsOfMeasure.ConvertUnits method. See lines 12-14.

Dim oInvApp As Inventor.Application = ThisApplication
Dim oMT As MeasureTools = oInvApp.MeasureTools
Dim oUOM As UnitsOfMeasure = oInvApp.UnitsOfMeasure
Dim oADoc As AssemblyDocument = TryCast(oInvApp.ActiveDocument, AssemblyDocument)
If oADoc Is Nothing Then Exit Sub
Dim oWrkPlanes As WorkPlanes = oADoc.ComponentDefinition.WorkPlanes
Dim oOcc As ComponentOccurrence
oOcc = oInvApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part...")
If oOcc Is Nothing Then Exit Sub
Dim oPoint As WorkPoint = oOcc.Definition.WorkPoints(1)
Dim oPrxPoint As WorkPointProxy : Call oOcc.CreateGeometryProxy(oPoint, oPrxPoint)
Dim dX As Double = Round(oUOM.ConvertUnits(oMT.GetMinimumDistance(oWrkPlanes(1), oPrxPoint), "cm", "in"), 3) ' YZ Plane
Dim dY As Double = Round(oUOM.ConvertUnits(oMT.GetMinimumDistance(oWrkPlanes(2), oPrxPoint), "cm", "in"), 3) ' XZ Plane
Dim dZ As Double = Round(oUOM.ConvertUnits(oMT.GetMinimumDistance(oWrkPlanes(3), oPrxPoint), "cm", "in"), 3) ' XY Plane
MessageBox.Show("X - " & dX & " in" & vbLf &
				"Y - " & dY & " in" & vbLf &
				"Z - " & dZ & " in", oOcc.Name)

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 5 of 8

chris
Advisor
Advisor

@Andrii_Humeniuk This is perfect, thank you!

0 Likes
Message 6 of 8

chris
Advisor
Advisor

@Andrii_Humeniuk what would I need to add to this rule so that when I click "OK" on the Message Box button, that it runs the rule again?

0 Likes
Message 7 of 8

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

I would recommend you to add a Do - Loop and Loop Repeat if Yes was selected. Example code:

Dim oInvApp As Inventor.Application = ThisApplication
Dim oMT As MeasureTools = oInvApp.MeasureTools
Dim oUOM As UnitsOfMeasure = oInvApp.UnitsOfMeasure
Dim oADoc As AssemblyDocument = TryCast(oInvApp.ActiveDocument, AssemblyDocument)
If oADoc Is Nothing Then Exit Sub
Dim oWrkPlanes As WorkPlanes = oADoc.ComponentDefinition.WorkPlanes
Dim oResult As DialogResult
Do
	Dim oOcc As ComponentOccurrence
	oOcc = oInvApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part...")
	If oOcc Is Nothing Then Exit Sub
	Dim oPoint As WorkPoint = oOcc.Definition.WorkPoints(1)
	Dim oPrxPoint As WorkPointProxy : Call oOcc.CreateGeometryProxy(oPoint, oPrxPoint)
	Dim dX As Double = Round(oUOM.ConvertUnits(oMT.GetMinimumDistance(oWrkPlanes(1), oPrxPoint), "cm", "in"), 3) ' YZ Plane
	Dim dY As Double = Round(oUOM.ConvertUnits(oMT.GetMinimumDistance(oWrkPlanes(2), oPrxPoint), "cm", "in"), 3) ' XZ Plane
	Dim dZ As Double = Round(oUOM.ConvertUnits(oMT.GetMinimumDistance(oWrkPlanes(3), oPrxPoint), "cm", "in"), 3) ' XY Plane
	oResult = MessageBox.Show("X - " & dX & " in" & vbLf &
								"Y - " & dY & " in" & vbLf &
								"Z - " & dZ & " in" & vbLf &
								"Yes - Repeat the action.", oOcc.Name, MessageBoxButtons.YesNo)
Loop While oResult = DialogResult.Yes

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 8 of 8

chris
Advisor
Advisor

@Andrii_Humeniuk Again thanks, on a side note, this would make a great "how to" video if you ever had time to record yourself breaking down each line and why you added it and what it does... for those of us trying to understand