Inventor Customization

Inventor Customization

Reply
Mentor
FarrenYoung
Posts: 264
Registered: ‎07-13-2009
Message 1 of 4 (350 Views)
Accepted Solution

How to transform occurrence to match another occurrence's UCS

350 Views, 3 Replies
08-09-2012 07:25 AM

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"
************************************************************************************

Hi Farren,

 

First of all, nice pictures :smileyhappy:

 

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. 

ADN Support Specialist
philippe.leefsma
Posts: 676
Registered: ‎06-02-2009
Message 2 of 4 (323 Views)

Re: How to transform occurrence to match another occurrence's UCS

08-10-2012 01:08 AM in reply to: FarrenYoung

Hi Farren,

 

First of all, nice pictures :smileyhappy:

 

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

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

Re: How to transform occurrence to match another occurrence's UCS

08-10-2012 08:33 AM in reply to: philippe.leefsma

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"
************************************************************************************
Distinguished Contributor
ADNpati
Posts: 126
Registered: ‎07-01-2012
Message 4 of 4 (256 Views)

Re: How to transform occurrence to match another occurrence's UCS

10-24-2012 10:13 PM in reply to: FarrenYoung

:smileyhappy: :smileyhappy:

 

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 -

-------------------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.