Inventor Engineer-to-Order

Inventor Engineer-to-Order

Reply
Active Contributor
justinrice
Posts: 27
Registered: ‎12-17-2009
Message 1 of 4 (256 Views)
Accepted Solution

Create a UCS in a Part

256 Views, 3 Replies
11-16-2012 07:14 AM

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

ETO 2014 SP1
Win7 X64
8GB RAM
Nvidia Quadro 2000M

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

Mentor
FarrenYoung
Posts: 264
Registered: ‎07-13-2009
Message 2 of 4 (250 Views)

Re: Create a UCS in a Part

11-16-2012 07:57 AM 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"
************************************************************************************
Active Contributor
justinrice
Posts: 27
Registered: ‎12-17-2009
Message 3 of 4 (244 Views)

Re: Create a UCS in a Part

11-16-2012 08:32 AM in reply to: FarrenYoung

That did it.

 

Thanks.

ETO 2014 SP1
Win7 X64
8GB RAM
Nvidia Quadro 2000M
Distinguished Contributor
ludesroc
Posts: 172
Registered: ‎05-03-2005
Message 4 of 4 (115 Views)

Re: Create a UCS in a Part

05-01-2014 06:59 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Manufacturing Community
The Manufacturing Community provides additional access to tips, tutorials, blogs and networking with peers.