- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello together,
I have a part with a UCS inside. This part is placed in an assembly. I would like create a new UCS in the assembly with the same orientation as the part UCS.
Dim oDoc As Document
oDoc = m_invApp.ActiveDocument
Dim CompDefs As AssemblyComponentDefinitions
CompDefs = oDoc.ComponentDefinitions
Dim oCompDef As AssemblyComponentDefinition
oCompDef = CompDefs.Item(1)
Dim oWx As Inventor.WorkAxis
oWx = m_invApp.CommandManager.Pick(SelectionFilterEnum.kWorkAxisFilter, "Please select WorkAxis:")
If oWx.IsCoordinateSystemElement Then
Dim oWxNodeDef As Inventor.NativeBrowserNodeDefinition
Dim oWxNode As Inventor.BrowserNode
oWxNodeDef = oDoc.BrowserPanes.GetNativeBrowserNodeDefinition(oWx)
oWxNode = oDoc.BrowserPanes.ActivePane.TopNode.AllReferencedNodes(oWxNodeDef).Item(1)
Dim oUCS As Inventor.UserCoordinateSystem
oUCS = oWxNode.Parent.NativeObject
Dim oTransMatrix As Matrix
oTransMatrix = oUCS.Transformation
'.........................
End If
How could I do this?
Thanks
Georg
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @GeorgK,
In order to copy UCS from part to assembly, UserCoordinateSystemProxy can be created from part and copied into AssemblyDocument.
To illustrate the same,
- Launch Inventor 2018
- open new assembly document
- Download attached part(UCS part.ipt) to desired location
- Copy and paste the following VBA code into VBA editor.
- Update the path of part in VBA code.
- On running the code, a UCS will be copied from part to assembly.
Sub Main()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim occMatrix As Matrix
Set occMatrix = ThisApplication.TransientGeometry.CreateMatrix
Dim occ As ComponentOccurrence
Set occ = oDef.Occurrences.Add("Path of part files\UCS part.ipt", occMatrix)
Dim compDef As PartComponentDefinition
Set compDef = occ.Definition
Dim partUCS As UserCoordinateSystem
Set partUCS = compDef.UserCoordinateSystems.Item(1)
Dim oProxy As UserCoordinateSystemProxy
Call occ.CreateGeometryProxy(partUCS, oProxy)
Dim oMatrix As Matrix
Set oMatrix = oProxy.Transformation
Dim oUCSDef As UserCoordinateSystemDefinition
Set oUCSDef = oDef.UserCoordinateSystems.CreateDefinition
oUCSDef.Transformation = oMatrix
Dim oUCS As UserCoordinateSystem
Set oUCS = oDef.UserCoordinateSystems.Add(oUCSDef)
End Sub
Please feel free to contact if there is any queries.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello @chandra.shekar.g,
is it possible to select the UCS directly? I have several parts with different UCS in each part.
Thank you for your help.
Georg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @GeorgK,
Try the following VBA code to select the UCS and create the same in AssemblyDocument.
Sub Main()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oUCS As UserCoordinateSystem
Set oUCS = ThisApplication.CommandManager.Pick(kUserCoordinateSystemFilter, "Select UCS")
Dim oMatrix As Matrix
Set oMatrix = oUCS.Transformation
Dim oUCSDef As UserCoordinateSystemDefinition
Set oUCSDef = oDef.UserCoordinateSystems.CreateDefinition
oUCSDef.Transformation = oMatrix
Dim copiedUCS As UserCoordinateSystem
Set copiedUCS = oDef.UserCoordinateSystems.Add(oUCSDef)
End Sub
Please feel free to contact if there is any queries.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello @chandra.shekar.g,
your code does not position the UCS in the assembly at the position where the part with the UCS is. The part includes the UCS.
Thank you Georg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @GeorgK,
Try the following VBA code to copy UCS from part to assembly. Here, location of part occurrence plays important role in copying UCS. So, occurrence selection is required to copy UCS.
Sub Main()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oUCS As UserCoordinateSystem
Set oUCS = ThisApplication.CommandManager.Pick(kUserCoordinateSystemFilter, "Select UCS")
Dim occ As ComponentOccurrence
Set occ = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Select occurrence from which UCS need to copy")
Dim occMatrix As Matrix
Set occMatrix = occ.Transformation
Dim oMatrix As Matrix
Set oMatrix = oUCS.Transformation
Call oMatrix.TransformBy(occMatrix)
Dim oUCSDef As UserCoordinateSystemDefinition
Set oUCSDef = oDef.UserCoordinateSystems.CreateDefinition
oUCSDef.Transformation = oMatrix
Dim copiedUCS As UserCoordinateSystem
Set copiedUCS = oDef.UserCoordinateSystems.Add(oUCSDef)
End Sub
Please feel free to contact if there is any queries.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello @chandra.shekar.g,
thank you very much. Now I understand the transformation. That's great. Is it possible to get the occurrence from the UCS by code?
Georg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @GeorgK,
Try the following VBA code which takes occurrence from UCS and copy UCS from part to assembly.
Sub Main()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oUCS As UserCoordinateSystem
Set oUCS = ThisApplication.CommandManager.Pick(kUserCoordinateSystemFilter, "Select UCS")
Dim occDef As ComponentDefinition
Set occDef = oUCS.Parent
Dim occ As ComponentOccurrence
Dim occMatrix As Matrix
For Each occ In oDef.Occurrences
If occ.Definition Is occDef Then
Set occMatrix = occ.Transformation
End If
Next
If occMatrix Is Nothing Then
Debug.Print ("UCS occurrence not found")
Else
Dim oMatrix As Matrix
Set oMatrix = oUCS.Transformation
Call oMatrix.TransformBy(occMatrix)
Dim oUCSDef As UserCoordinateSystemDefinition
Set oUCSDef = oDef.UserCoordinateSystems.CreateDefinition
oUCSDef.Transformation = oMatrix
Dim copiedUCS As UserCoordinateSystem
Set copiedUCS = oDef.UserCoordinateSystems.Add(oUCSDef)
End If
End Sub
Please feel free to contact if there is any queries.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello @chandra.shekar.g,
is it possible to get the UCS from a part in a subassembly? How do I transforme the matrix?
Thank you
Georg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @GeorgK,
You could try the following VBA code. Here, only part occurrences are considered.
Sub Main()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oUCS As UserCoordinateSystem
Set oUCS = ThisApplication.CommandManager.Pick(kUserCoordinateSystemFilter, "Select UCS")
Dim occDef As ComponentDefinition
Set occDef = oUCS.Parent
Dim occ As ComponentOccurrence
Dim occMatrix As Matrix
For Each occ In oDef.Occurrences.AllLeafOccurrences
If occ.Definition Is occDef Then
Set occMatrix = occ.Transformation
Exit For
End If
Next
If occMatrix Is Nothing Then
Debug.Print ("UCS occurrence not found")
Else
Dim oMatrix As Matrix
Set oMatrix = oUCS.Transformation
Call oMatrix.TransformBy(occMatrix)
Dim oUCSDef As UserCoordinateSystemDefinition
Set oUCSDef = oDef.UserCoordinateSystems.CreateDefinition
oUCSDef.Transformation = oMatrix
Dim copiedUCS As UserCoordinateSystem
Set copiedUCS = oDef.UserCoordinateSystems.Add(oUCSDef)
End If
End Sub
Please feel free to contact if there is any queries.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report