Align part to assembly ucs

Align part to assembly ucs

Anonymous
Not applicable
2,389 Views
4 Replies
Message 1 of 5

Align part to assembly ucs

Anonymous
Not applicable

 

I want to add parts to an assembly and align them with the assembly ucs. The parts have a ucs placed on the with the correct orientation. The idea is to have all the parts in an assembly with the correct side up and aligned the correct way for router cutting.

Below is the code I have tried without success. Any help would be appreciated.

 

Dim oAssm As Inventor.AssemblyDocument
Dim oOcc As Inventor.ComponentOccurrence
Dim oMatrix As Inventor.Matrix

' Open an assembly template
oAssm = ThisApplication.Documents.Open(oTDir.TemplateDir & "Standard.iam")

' Add the part to the assembly
oOcc = oAssm.ComponentDefinition.Occurrences.Add(ReturnFieldValue(GlobalRouterList.Item(I), 1), oMatrix)

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

' Define the origin point.
Dim oPartOrigin As Point = Nothing
Dim oAssmOrigin As Point = Nothing

' Define the axis vectors.
Dim oPartXAxis As Vector = Nothing
Dim oPartYAxis As Vector = Nothing
Dim oPartZAxis As Vector = Nothing
Dim oAssmXAxis As Vector = Nothing
Dim oAssmYAxis As Vector = Nothing
Dim oAssmZAxis As Vector = Nothing

' Create the matrix and define the desired coordinate system.
Dim oAssmMatrix As Inventor.Matrix = oTG.CreateMatrix


Call oAssmMatrix.GetCoordinateSystem(oAssmOrigin, oAssmXAxis, oAssmYAxis, oAssmZAxis)
Call oMatrix.GetCoordinateSystem(oPartOrigin, oPartXAxis, oPartYAxis, oPartZAxis)

Call oMatrix.SetToAlignCoordinateSystems(oPartOrigin, oPartXAxis, oPartYAxis, oPartZAxis, oAssmOrigin, oAssmXAxis, oAssmYAxis, oAssmZAxis)

oAssm.Update()

 

Malcolm

0 Likes
Accepted solutions (1)
2,390 Views
4 Replies
Replies (4)
Message 2 of 5

nmunro
Collaborator
Collaborator
Accepted solution

The attached text file contains a VBA routine to align the UCS in a part with the top level assembly coordinate system. This solution requires that you be using Inventor 2013 or newer. Import the vba routine into the Inventor Application project for testing.

 

The routine makes a few assumptions and does not check for any errors:

 

 - The part occurrence with the UCS of interest must be the only item in the current selection set.

 - The ucs of interest in the part is the first UCS feature in the part.

 

Select the occurrence in the assembly, and run the macro.

 

Neil

        


https://c3mcad.com

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks Neil that was exactly what I was looking for.

0 Likes
Message 4 of 5

Anonymous
Not applicable

I'm sorry, but I presume this is different from constraining ucs to usc using the constrain dialog?

 

I'd like to know, because I am looking for a way to rebase the origin of parts in an assembly.

0 Likes
Message 5 of 5

nmunro
Collaborator
Collaborator

Yes, a bit different in that the assembly does not require a UCS be created that duplicates the assembly coordinate system. If you placed an assembly UCS aligned with the assembly coordinate system you could use a constraint set to obtain the same behavior without code.

 

Neil

 

        


https://c3mcad.com

0 Likes