Hide Table of Contents

Add Distance Mates Example (VBA)

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



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Add Distance Mates Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:




x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2012 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.