MACRO LIBRARY

Add mate to selected entities

Free public access. No account or subscription required.

Files

Add mate to selected entities

Code

Module: mMain

'Quickly add a profile mate. This macro can be easily modified to add a different _
    type of mate by changing the first argument in IAssemblyDoc::AddMate5.
    
'Setup requires Tools-->Customize:
'1. Create three macro buttons on the command manager in an assembly, with each
'   button pointing to a different sub procedure.
'2. Create a keyboard shortcut associated with these macro buttons.
    
'Usage:
'1. Select the two mate faces in the display area.
'2. Run desired shortcut to create an aligned or anti-aligned mate.
'3. If wrong alignment, hit Ctrl Z (undo) and use other alignment.
'4. If additional mate properties need to be modified, run the shortcut to
'   edit the mate. This will open the PropertyManager page of the last added
'   feature, if it was a mate.
    
'Errors:
'See swAddMateError_e for a listing of errors.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Option Compare Text
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swFeat As SldWorks.Feature
Dim lngErr As Long
    
Sub Aligned()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    swAssy.AddMate5 swMatePROFILECENTER, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, False, 0, lngErr
    If lngErr <> 1 Then swApp.SendMsgToUser "Mate failed with error code " & lngErr
End Sub
    
Sub AntiAligned()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    swAssy.AddMate5 swMatePROFILECENTER, 1, False, 0, 0, 0, 0, 0, 0, 0, 0, False, False, 0, lngErr
    If lngErr <> 1 Then swApp.SendMsgToUser "Mate failed with error code " & lngErr
End Sub
    
Sub EditMate()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swFeat = swModel.Extension.GetLastFeatureAdded
    If InStr(swFeat.GetTypeName, "mate") <> 0 Then
        swFeat.Select False
        swApp.RunCommand swCommands_EditFeature, Empty
    End If
End Sub