MACRO LIBRARY

Align components' origins and default planes

Free public access. No account or subscription required.

Files

Align component to another component's origin and default planes

Code

'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'Preconditions: transform_test.SLDASM is open and two components are selected.
'Postconditions: Selected assembly component is aligned exactly (according to origin _
    and planes) of other component.
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp1 As SldWorks.Component2
Dim swComp2 As SldWorks.Component2
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swComp1 = swSelMgr.GetSelectedObjectsComponent3(1, 0)
    Set swComp2 = swSelMgr.GetSelectedObjectsComponent3(2, 0)
    
    'sets component transforms (location and rotation) equal to one another
    swComp1.Transform2 = swComp2.Transform2
    
    'assy must be rebuilt to see results
    swModel.EditRebuild3
End Sub