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
Any help is greatly appreciated!
Thanks,
Solved! Go to Solution.
Solved by philippe.leefsma. Go to Solution.
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.
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!
Hey Farren... Can you please post the code, am looking some thing similar here.
May be I can use the logic..
Thanks Mate..