Hide Table of Contents

Get Mate Definition Example (VBA)

This example shows how to retrieve the mate definition.

 

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

'

' Preconditions:

'         (1) Assembly document is open.

'         (2) Mate is selected.

'

' Postconditions: None

'

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

Option Explicit

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

    swAlignNONE = 0

    swAlignSAME = 1

    swAlignAGAINST = 2

End Enum

Public Enum swMateEntity2ReferenceType_e

    swMateEntity2ReferenceType_Point = 0

    swMateEntity2ReferenceType_Line = 1

    swMateEntity2ReferenceType_Circle = 2

    swMateEntity2ReferenceType_Plane = 3

    swMateEntity2ReferenceType_Cylinder = 4

    swMateEntity2ReferenceType_Sphere = 5

    swMateEntity2ReferenceType_Set = 6

    swMateEntity2ReferenceType_Cone = 7

    swMateEntity2ReferenceType_SweptSurface = 8

    swMateEntity2ReferenceType_MultipleSurface = 9

    swMateEntity2ReferenceType_GenSurface = 10

    swMateEntity2ReferenceType_Ellipse = 11

    swMateEntity2ReferenceType_GeneralCurve = 12

    swMateEntity2ReferenceType_UNKNOWN = 13

End Enum

Public Enum swInConfigurationOpts_e

    swConfigPropertySuppressFeatures = 0

    swThisConfiguration = 1

    swAllConfiguration = 2

    swSpecifyConfiguration = 3

End Enum

 

Sub ProcessDisplayDimension _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swDispDim As SldWorks.DisplayDimension, _

    nVarFactor As Double, _

    sVarType As String _

)

    Dim swDim                   As SldWorks.Dimension

    Dim vDimValueArr            As Variant

    

    If Nothing Is swDispDim Then

        Debug.Print "      No display dimension"

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

        Exit Sub

    End If

    Set swDim = swDispDim.GetDimension

    

    vDimValueArr = swDim.GetSystemValue3(swThisConfiguration, Empty)

    Debug.Assert Not IsEmpty(vDimValueArr)

    Debug.Assert 0 = UBound(vDimValueArr)

 

    ' Show name and value of dimension

    Debug.Print "      Dim Name      = " & swDim.FullName

    Debug.Print "      Dim Value     = " & vDimValueArr(0) * nVarFactor & sVarType

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

End Sub

 

Sub ProcessMateEntity _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swMateEnt As SldWorks.MateEntity2 _

)

    Dim swComp                  As SldWorks.Component2

    Dim vEntParam               As Variant

    

    If Nothing Is swMateEnt Then

        Debug.Print "      No mate entity"

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

        Exit Sub

    End If

    Set swComp = swMateEnt.ReferenceComponent: Debug.Assert Not Nothing Is swComp

    

    vEntParam = swMateEnt.EntityParams

    Debug.Assert Not IsEmpty(vEntParam)

    Debug.Assert 7 = UBound(vEntParam)

    ' Show name of mate component entity and its parameters

    Debug.Print "      Ref Comp  = " & swComp.Name2

    Debug.Print "      Location  = (" & vEntParam(0) * 1000# & ", " & vEntParam(1) * 1000# & ", " & vEntParam(2) * 1000# & ") mm"

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

    Debug.Print "      Radius 1  = " & vEntParam(6) * 1000# & " mm"

    Debug.Print "      Radius 2  = " & vEntParam(7) * 1000# & " mm"

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

End Sub

 

Sub ProcessMate _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swMate As SldWorks.Mate2 _

)

    Dim sVarType                As String

    Dim nVarFactor              As Double

    

    Dim nNumMateEnt             As Long

    Dim i                       As Long

 

    ' Get the number of entities for the selected mate

    nNumMateEnt = swMate.GetMateEntityCount

    

    ' If mate type is Angle or Distance, then set conversion values

    Select Case swMate.Type

        Case swMateANGLE

            sVarType = " deg"

            nVarFactor = 57.3

            

        Case swMateDISTANCE

            sVarType = " mm"

            nVarFactor = 1000#

    End Select

    ' Show if mate is aligned and can be flpped

    Debug.Print "    Alignment          = " & swMate.alignment

    Debug.Print "    CanBeFlipped       = " & swMate.CanBeFlipped

    ' If mate is Angle or Distance, show variances

    If swMateANGLE = swMate.Type Or swMateDISTANCE = swMate.Type Then

        Debug.Print "    MaximumVariation   = " & swMate.MaximumVariation * nVarFactor & sVarType

        Debug.Print "    MinimumVariation   = " & swMate.MinimumVariation * nVarFactor & sVarType

    End If

    ' Show type of mate

    Debug.Print "    Type               = " & swMate.Type

    

    ProcessDisplayDimension swApp, swModel, swMate.DisplayDimension, nVarFactor, sVarType

    

    For i = 0 To nNumMateEnt - 1

        ProcessMateEntity swApp, swModel, swMate.MateEntity(i)

    Next i

End Sub

 

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swFeat                  As SldWorks.feature

    Dim swMate                  As SldWorks.Mate2

    Dim bRet                    As Boolean

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swFeat = swSelMgr.GetSelectedObject5(1)

    Set swMate = swFeat.GetSpecificFeature2

    

    Debug.Print "File = " & swModel.GetPathName

    ' Show name of selected feature (in this case, a mate) and name of feature

    Debug.Print "  " & swFeat.Name & " [" & swFeat.GetTypeName & "]"

    

    ProcessMate swApp, swModel, swMate

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 Mate Definition 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.