Hide Table of Contents

Get Mates and Mate Entities Example (VBA)

This example shows how to traverse a FeatureManager design tree and get all of the assemblies mates and mate entities.

 

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

'

' Preconditions: Assembly document is open.

'

' Postconditions: None

'

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

Option Explicit

Public Enum swSelectType_e

    swSelNOTHING = 0

    swSelEDGES = 1          '  "EDGE"

    swSelFACES = 2          '  "FACE"

    swSelVERTICES = 3       '  "VERTEX"

    swSelDATUMPLANES = 4    '  "PLANE"

    swSelDATUMAXES = 5      '  "AXIS"

    

    swSelREFEDGES = 51      '  "REFERENCE-EDGE"

    swSelREFFACES = 52

End Enum

 

Public Enum swMateType_e

    swMateCOINCIDENT = 0

    swMateCONCENTRIC = 1

    swMatePERPENDICULAR = 2

    swMatePARALLEL = 3

    swMateTANGENT = 4

    swMateDISTANCE = 5

    swMateANGLE = 6

    swMateUNKNOWN = 7

    swMateSYMMETRIC = 8

    swMateCAMFOLLOWER = 9

    swMateGEAR = 10

End Enum

 

Public Enum swMateAlign_e

    swMateAlignALIGNED = 0

    swMateAlignANTI_ALIGNED = 1

    swMateAlignCLOSEST = 2

End Enum

 

Public Enum swMateEntityTypes_e

    swMateUnsupported = 0

    swMatePoint = 1

    swMateLine = 2

    swMatePlane = 3

    swMateCylinder = 4

    swMateCone = 5

    swMateSphere = 6

    swMateCircle = 7

End Enum

 

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swFeat                      As SldWorks.feature

    Dim swMateFeat                  As SldWorks.feature

    Dim swSubFeat                   As SldWorks.feature

    Dim swMate                      As SldWorks.Mate2

    Dim swComp                      As SldWorks.Component2

    Dim swMateEnt(2)                As SldWorks.MateEntity2

    Dim i                           As Integer

       

    

    ' Disable Visual Basic error on implicit Query Interface

    On Error Resume Next

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swFeat = swModel.FirstFeature

    

    Debug.Print "File = " & swModel.GetPathName

    

    ' Iterate over features in FeatureManager design tree

    Do While Not swFeat Is Nothing

        If "MateGroup" = swFeat.GetTypeName Then

            Set swMateFeat = swFeat

            Exit Do

        End If

        Set swFeat = swFeat.GetNextFeature

    Loop

    

    Debug.Print "  " & swMateFeat.Name

    

    ' Get first mate, which is a subfeature

    Set swSubFeat = swMateFeat.GetFirstSubFeature

    Do While Not swSubFeat Is Nothing

       Set swMate = swSubFeat.GetSpecificFeature2

        

        If Not swMate Is Nothing Then

            Debug.Print "    " & swSubFeat.Name

            Debug.Print ""

            

            For i = 0 To 1

                                         

                Set swMateEnt(i) = swMate.MateEntity(i)

                         

                                

                Debug.Print "    " & swSubFeat.Name

                Debug.Print "      Type         = " & swMate.Type

                Debug.Print "      AlignFlag    = " & swMate.alignment

                Debug.Print "      CanBeFlipped = " & swMate.CanBeFlipped

                Debug.Print ""

                

                Set swComp = swMateEnt(i).ReferenceComponent

                Debug.Print "      Component    = " & swComp.Name2

                

                Debug.Print "      MateEntType  = " & swMateEnt(i).ReferenceType

                Debug.Print "      (x,y,z)      = (" & swMateEnt(i).EntityParams(0) & ", " & swMateEnt(i).EntityParams(1) & ", " & swMateEnt(i).EntityParams(2) & ")"

                Debug.Print "      (i,j,k)      = (" & swMateEnt(i).EntityParams(3) & ", " & swMateEnt(i).EntityParams(4) & ", " & swMateEnt(i).EntityParams(5) & ")"

                Debug.Print "      Radius 1     = " & swMateEnt(i).EntityParams(6)

                Debug.Print "      Radius 2     = " & swMateEnt(i).EntityParams(7)

                Debug.Print ""

            Next i

            Debug.Print "    ------------------------------------------------"

        End If

        

        ' Get the next mate in MateGroup

        Set swSubFeat = swSubFeat.GetNextSubFeature

    Loop

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:   Get Mates and Mate Entities 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.