
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.