Hi,
I have a quiet simple question. How can I get the xyz position of a part/ComponentOccurrence in an assembly.
I did some tests and found the Transformation.Translation vector.
But the values for x, y and z are only one tenth of the real value (e.g. x is 2222, but the vector.x property gives me 222.2).
My assembly untis are in mm.
Regards Andreas
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Solved by bshbsh. Go to Solution.
inventor always uses centimeters internally. you need to convert it to the units you need (eg. the model units). it's simple in the case of cm-mm, but there are built-in unit conversion functions as well.
Sample:
Sub Main() On Error Goto Handler: Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument If oDoc Is Nothing Then Exit Sub End If 'Ensure you are at the right point to select objects. Select Case True Case Not oDoc.ActivatedObject Is Nothing If oDoc.ActivatedObject.Type = ObjectTypeEnum.kDocumentObject Then oDoc = oDoc.ActivatedObject Else MsgBox ("Invalid active object") Exit Sub End If Case oDoc.ActivatedObject Is Nothing 'Continue without revising anything Case Else MsgBox ("Invalid Activated Object!") End Select On Error Goto 0 Dim oSS As SelectSet oSS = oDoc.SelectSet If oSS.Count >= 1 Call ProcessBulkLocations(oSS) End If Exit Sub Handler: MsgBox("Doc Not an Assembly!") End Sub Sub ProcessBulkLocations(oSS As SelectSet) For Each oItem In oSS If oItem.Type = ObjectTypeEnum.kComponentOccurrenceObject Then Call GetOccOrigin(oItem) End If Next End Sub Sub GetOccOrigin(oOcc As ComponentOccurrence) Dim oUOM As UnitsOfMeasure oUOM = ThisApplication.ActiveDocument.UnitsOfMeasure ' Get the current transformation matrix from the occurrence. Dim oTransform As Matrix oTransform = oOcc.Transformation Dim oOriginLocation As Vector oOriginLocation = oTransform.Translation ptX = oUOM.ConvertUnits(oOriginLocation.X, "cm", "in") ptY = oUOM.ConvertUnits(oOriginLocation.Y, "cm", "in") ptZ = oUOM.ConvertUnits(oOriginLocation.Z, "cm", "in") MsgBox(ptX & vbLf & ptY & vbLf & ptZ) ' Move the occurrence honoring any existing constraints. ''oTransform.SetTranslation ThisApplication.TransientGeometry.CreateVector(2, 2, 3) ''oOccurrence.Transformation = oTransform ' Move the occurrence ignoring any constraints. 'Anything that causes the assembly to recompute will cause the 'occurrence to reposition itself to honor the constraints. ''oTransform.SetTranslation ThisApplication.TransientGeometry.CreateVector(3, 4, 5) ''Call oOccurrence.SetTransformWithoutConstraints(oTransform) End Sub
Thank you Justin for the snippet and thank you János for the information, that Inventor always uses cm internally.
Regards Andreas
Hi,
I think I have a similar request. I have this assembly with a form where the user can choose between having 1, 2 or 3 of the same part (but 3 different occurrences)
Those parts are constrained in 2 axis, but can move freely in the third axis. I'd like to be able to capture, or get, the current position of those parts somehow and put that one coordinate in a parameter that can be exported into a XML file.
So I made this dummy assembly that recreates exactly the problem that I have, just not the real thing. There's a form in there that should open with the document. In that form you have the option to load 1, 2 or 3 parts, and the ability to save the parameters to a XML .
But right now, I really don't know where to start to capture that position. And I'm a beginner in VB and iLogic so that code above really makes very little sense to me. My plan B would be to constrain those parts to some plane and have a slider change the offset, but at first, I'd like to see if there's a more elegant way of doing this. Also, I like that very intuitive way of just grabbing the part and positioning it manually (without having to rely on a slider), I'd like to retain that.
I guess I just need someone to either, explain that snippet above, or send me in some direction to help me start.
Can't find what you're looking for? Ask the community or share your knowledge.