This example shows how to add distance mates.
'---------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim assy As SldWorks.AssemblyDoc
Dim longstatus As Long
Dim mateFeature As Object
Dim mateSelMark As Long
Dim numberOfMatesCreated As Long
Sub main()
Set swApp = Application.SldWorks
Set assy = swApp.ActiveDoc
mateSelMark = 1
numberOfMatesCreated = 0
' Frame #1
' Front plane Mate
assy.ClearSelection2 True
boolStat = swApp.ActiveDoc.Extension.SelectByID2("Front@CLM24BT-94@Before Macro", "PLANE", 0, 0, 0, True, mateSelMark, Nothing, swSelectOptionDefault)
If Not boolStat Then MsgBox "Selection error! " & "Front@CLM24BT-94@Before Macro"
boolStat = swApp.ActiveDoc.Extension.SelectByID2("Front@UF8024GL-1@Before Macro", "PLANE", 0, 0, 0, True, mateSelMark, Nothing, swSelectOptionDefault)
If Not boolStat Then MsgBox "Selection error! " & "Front@UF8024GL-1@Before Macro"
Set mateFeature = assy.AddMate3(5, 0, False, 2.54000000001016E-02, 0, 0, 0, 0, 0, 0, 0, False, longstatus)
If mateFeature Is Nothing Then
MsgBox "Frame #1 : Front plane mate failed! "
Else
numberOfMatesCreated = numberOfMatesCreated + 1
End If
'---------------------------------------------
' Top plane mate
assy.ClearSelection2 True
boolStat = swApp.ActiveDoc.Extension.SelectByID2("Top@CLM24BT-94@Before Macro", "PLANE", 0, 0, 0, True, mateSelMark, Nothing, swSelectionOptionDefault)
If Not boolStat Then MsgBox "Selection error! " & "Top@CLM24BT-94@Before Macro"
boolStat = swApp.ActiveDoc.Extension.SelectByID2("Top@UF8024GL-1@Before Macro", "PLANE", 0, 0, 0, True, mateSelMark, Nothing, swSelectOptionDefault)
If Not boolStat Then MsgBox "Selection error! " & "Top@UF8024GL-1@Before Macro"
Set mateFeature = assy.AddMate3(5, 0, True, 5.56260000002225E-03, 0, 0, 0, 0, 0, 0, 0, False, longstatus)
If mateFeature Is Nothing Then
MsgBox "Frame #1 : Top plane mate failed! "
Else
numberOfMatesCreated = numberOfMatesCreated + 1
End If
'---------------------------------------------
' Right plane mate
assy.ClearSelection2 True
boolStat = swApp.ActiveDoc.Extension.SelectByID2("Right@CLM24BT-94@Before Macro", "PLANE", 0, 0, 0, True, mateSelMark, Nothing, swSelectOptionDefault)
If Not boolStat Then MsgBox "Selection error! " & "Right@CLM24BT-94@Before Macro"
boolStat = swApp.ActiveDoc.Extension.SelectByID2("Right@UF8024GL-1@Before Macro", "PLANE", 0, 0, 0, True, mateSelMark, Nothing, swSelectOptionDefault)
If Not boolStat Then MsgBox "Selection error! " & "Right@UF8024GL-1@Before Macro"
Set mateFeature = assy.AddMate3(5, 0, False, 0.266700000001067, 0, 0, 0, 0, 0, 0, 0, False, longstatus)
If mateFeature Is Nothing Then
MsgBox "Frame #1 : Right plane mate failed! "
Else
numberOfMatesCreated = numberOfMatesCreated + 1
End If
'--------------------------------------
assy.ClearSelection2 True
Dim strMessage As String
strMessage = "Number of mates created = "
strMessage = strMessage + CStr(numberOfMatesCreated)
MsgBox strMessage
End Sub