Inventor Engineer-To-Order (Read-Only)
Welcome to Autodesk’s Inventor ETO Forums. Share your knowledge, ask questions, and explore popular Inventor ETO topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a UCS in a Part

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
justinrice
685 Views, 3 Replies

Create a UCS in a Part

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

Engineering Intent
JustinRice@EngineeringIntent.com
3 REPLIES 3
Message 2 of 4
FarrenYoung
in reply to: justinrice

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

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 3 of 4
justinrice
in reply to: FarrenYoung

That did it.

 

Thanks.

Engineering Intent
JustinRice@EngineeringIntent.com
Message 4 of 4
ludesroc
in reply to: FarrenYoung

Hi Farren, In the case where the return value type is a document, how would you write the code? I have an Assy with 2 parts. I get the workpoints from part1 and pass them to part2. When this Assy is the root, everything works fine but if the Assy is a sub assy then most often than not I get a NoValue error when evaluating gethostobject(myPart) ! If myPart.Parent = Root Then oPartDoc = gethostobject(myPart).Definition.Document oPartCompDef = oPartDoc.ComponentDefinition Else oPartDoc = gethostobject(myPart) 'Works sometimes!!! oPartCompDef = oPartDoc.ComponentDefinition End If Regards,
Ludesroc

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report