I'm trying to create a UCS in a part but the code below always creates the UCS in the Root assembly. What am I missing?
This rule and child is written in the intended part design
Rule CreateUCS As Any
' Get the Active Part
Dim oDoc As Any = %%InventorApplication.ActiveDocument
' Set a reference to the PartComponentDefinition object
Dim oCompDef As Any = oDoc.ComponentDefinition
' Create an empty definition object
Dim oUCSDef As Any = oCompDef.UserCoordinateSystems.CreateDefinition()
'Create the UCS
Dim oUCS As Any = oCompDef.UserCoordinateSystems.Add(oUCSDef)
'Name the X Cord for the UCS
'Set the X Cord for the UCS
Dim oXParm As Any = oUCS.XOffset
oXParm.Name = "UCS" & "1" & "X"
oXParm.Value = 1 * 2.54
'Name the Y Cord for the UCS
'Set the Y Cord for the UCS
Dim oYParm As Any = oUCS.YOffset
oYParm.Name = "UCS" & "1" & "Y"
oYParm.Value = 1 * 2.54
'Name the Z Cord for the UCS
'Set the Z Cord for the UCS
Dim oZParm As Any = oUCS.ZOffset
oZParm.Name = "UCS" & "1" & "Z"
oZParm.Value = 1 * 2.54
'Name the X Rotation Angle for the UCS
Dim oXRParm As Any = oUCS.XAngle
oXRParm.Name = "UCS" & "1" & "XR"
oXRParm.Value = 0
'Name the Y Rotation Angle for the UCS
Dim oYRParm As Any = oUCS.YAngle
oYRParm.Name = "UCS" & "1" & "YR"
oYRParm.Value = 0
'Name the Z Rotation Angle for the UCS
Dim oZRParm As Any = oUCS.ZAngle
oZRParm.Name = "UCS" & "1" & "ZR"
oZRParm.Value = 0
Return oUCS
End Rule
Child UCS As :BasePart
render? = typeCheck(CreateUCS, :Any)
End Child
Solved! Go to Solution.
Solved by FarrenYoung. Go to Solution.
I am assuming this line has something to do with it
Dim oDoc As Any = %%InventorApplication.ActiveDocument
Most likely the root document is the active document.
Try
Dim oDoc As Any = gethostobject(me).Definition.Document
You will want to check the type of the value returned there because sometimes "gethostobject(me)" will return a document and other times a componentOccurrence. Usually it is componentoccurrence that is why I added the ".definition.document" portion