Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to transform occurrence to match another occurrence's UCS

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
FarrenYoung
1143 Views, 3 Replies

How to transform occurrence to match another occurrence's UCS

I'm looking for some help "mating" user coordinate systems without constraints.  The components will be placed at precise positions and grounded.

 

Basically I want to place parts and have them automatically connect to each other based on pre-existing UCSs on the assemblies.  I have a 'ucs_in' and a 'ucs_out' on each assembly.  I want the inserted component to perform a transformation to make the new occurrence's ucs_in to "mate" to the previous occurrences ucs_out.  By mate I mean their center points are at the same location and all axes are pointing in the same direction.  I have included screenshots to show what I'm working with and what I am trying to accomplish.  I have also attached the project files.

 

 

Below is my attempt at the code to do this.  My experience with transformations is limited so I may be way off from where I need to be.

 

Sub UcsMate()
    Dim doc As AssemblyDocument
    Set doc = ThisApplication.ActiveDocument
    
    'assuming both occurrences are already in the assembly and both have 2 UCS, "ucs_in" and "ucs_out"
    
    Dim occ1 As ComponentOccurrence
    Dim occ2 As ComponentOccurrence
    
    Dim occ1_uOut As UserCoordinateSystem
    Dim occ2_uIn As UserCoordinateSystem
    
    Dim occ1_cdef As AssemblyComponentDefinition
    Dim occ2_cdef As AssemblyComponentDefinition
        
    Set occ1 = doc.ComponentDefinition.Occurrences.Item(1) 'horizontal elbow
    Set occ2 = doc.ComponentDefinition.Occurrences.Item(2) 'straight
    
    Set occ1_cdef = occ1.Definition
    Set occ2_cdef = occ2.Definition
    
    Set occ1_uOut = occ1_cdef.UserCoordinateSystems.Item("ucs_out")
    Set occ2_uIn = occ2_cdef.UserCoordinateSystems.Item("ucs_in")
    
    'assuming occ1 is already placed in the assembly how we want it
    
    'do i need to take into account that the origin/orientation of the newly added (in this case occ2) occurrence is likely not the same as the ucs_in?
    'i thought i could set the occurrence coordinate system to that of the ucs_in, but it doesn't seem to have any affect.  this step may not be required
    Call occ2.Transformation.SetCoordinateSystem(occ2_uIn.Origin.Point, occ2_uIn.XAxis.Line.Direction.AsVector(), occ2_uIn.YAxis.Line.Direction.AsVector(), occ2_uIn.ZAxis.Line.Direction.AsVector())
    
    
    'here is the attempt to transform the new/second occurrence to match the first/previous occurrence
    Call occ2.Transformation.SetToAlignCoordinateSystems(occ2_uIn.Origin.Point, occ2_uIn.XAxis.Line.Direction.AsVector(), occ2_uIn.YAxis.Line.Direction.AsVector(), occ2_uIn.ZAxis.Line.Direction.AsVector(), _
                                                   occ1_uOut.Origin.Point, occ1_uOut.XAxis.Line.Direction.AsVector(), occ1_uOut.YAxis.Line.Direction.AsVector(), occ1_uOut.ZAxis.Line.Direction.AsVector())
                                                    
    doc.Update
    
End Sub

 

 

Code Example.jpg

 

 

End Goal

 

Exploded view showing how ucs should mate.jpg

 

 

 

Any help is greatly appreciated!

 

Thanks,

 

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
3 REPLIES 3
Message 2 of 4

Hi Farren,

 

First of all, nice pictures 🙂

 

I closed your case logged from ADN and will continue any related correspondance in this forum thread, since we are in the initiative of pushing public support through forums. Also keep in mind the answering delay in forum is 5 business days against 3 in ADN support and 24h in ADN Professional support.

 

I think the method you are looking for is "Matrix.SetToAlignCoordinateSystems". This so do all the work for you. Once you built the transformation matrix based on your ucs in/out, simply transform occurrence1 by the matrix.

 

Please take a look the the API Help Files if you need more information on that API.

 

Regards,

Philippe. 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

Thanks Philippe,

 

I was trying to use the SetToAlignCoordinateSystems method on the occurrence.transformation instead of creating a new matrix and then using SetToAlignCoordinateSystems on it then setting the occurrence transformation to the new matrix.  That did the trick.  Thanks a lot!

--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 4 of 4
ADNpati
in reply to: FarrenYoung

Smiley Happy Smiley Happy

 

Hey Farren... Can you please post the code, am looking some thing similar here.

 

May be I can use the logic..

 

Thanks Mate..

Mechanical Engineer
Inventor Applications Engineer

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -

-------------------------------------------------------------------------------------

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

Post to forums  

Autodesk Design & Make Report