Hide Table of Contents

Insert Mate Reference Example (VBA)

This example shows how to insert a mate reference.

'----------------------------------------------------------------------------

' Preconditions: Open:

' <SOLIDWORKS_install_dir>\samples\HandsOn\mate references\crank-arm.sldprt

'

' Postconditions:

' A mate reference, MateReference1, is inserted in the MateReferences folder

' in the FeatureManager design tree.

' NOTE: Because this part is used in a SOLIDWORKS online tutorial,

' do not save any changes when you close it.

'----------------------------------------------------------------------------

Option Explicit

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim swModelDocExt As SldWorks.ModelDocExtension

    Dim swSelMgr As SldWorks.SelectionMgr

    Dim swFeatMgr As SldWorks.FeatureManager

    Dim swFeature As SldWorks.Feature

    Dim mateRef1 As Object, mateRef2 As Object, mateRef3 As Object

    Dim boolstatus As Boolean

    Dim strMateRefName As String

       

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swModelDocExt = swModel.Extension

    Set swSelMgr = swModel.SelectionManager

    Set swFeatMgr = swModel.FeatureManager

  

    swModel.ClearSelection2 True

    

    ' Select three faces

    boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.007841429441271, 0.004702510345794, 0.007840974544081, False, 0, Nothing, 0)

        Set mateRef1 = swSelMgr.GetSelectedObject6(1, -1)

    boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.06256195446167, 0.003271675226301, 0.004687091733047, False, 0, Nothing, 0)

        Set mateRef2 = swSelMgr.GetSelectedObject6(1, -1)

    boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.04319534991731, 0.006350000000054, 0.009894144482189, False, 0, Nothing, 0)

        Set mateRef3 = swSelMgr.GetSelectedObject6(1, -1)

    swModel.ClearSelection2 True

  

    strMateRefName = "MateReference1"

 

    ' Insert mate reference

    Set swFeature = swFeatMgr.InsertMateReference2(strMateRefName, mateRef1, swMateReferenceType_Concentric, swMateReferenceAlignment_Aligned, False, mateRef2, swMateReferenceType_Concentric, swMateReferenceAlignment_AntiAligned, False, mateRef3, swMateReferenceType_Concentric, swMateReferenceAlignment_Closest)

   

    If swFeature Is Nothing Then

        MsgBox "Failed to insert mate reference."

    End If

   

    swModel.ClearSelection2 True

   

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:   Insert Mate Reference 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) 2015 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.