Hide Table of Contents

Get Mates Example (VB.NET)

This example shows how to get all of the mates (IMate2 and IMateInPlace objects) for all components in an assembly.

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

' Preconditions: Open: <Solidworks_install_dir>\samples\tutorial\smartcomponents\stepped_shaft.sldasm

'

' Postconditions: None

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

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System

Imports System.Diagnostics

 

Partial Class SolidWorksMacro

    Public Sub main()

 

        Dim swModel As ModelDoc2

        Dim swComponent As Component2

        Dim swAssembly As AssemblyDoc

        Dim Components As Object

        Dim SingleComponent As Object

        Dim Mates As Object

        Dim SingleMate As Object

        Dim swMate As Mate2

        Dim swMateInPlace As MateInPlace

        Dim numMateEntities As Integer

        Dim typeOfMate As Integer

        Dim i As Integer

 

        swModel = swApp.ActiveDoc

        swAssembly = swModel

 

        Components = swAssembly.GetComponents(False)

        For Each SingleComponent In Components

            swComponent = SingleComponent

            Debug.Print("Name of component: " & swComponent.Name2)

            Mates = swComponent.GetMates()

            If Not Mates Is Nothing Then

                For Each SingleMate In Mates

                    If TypeOf SingleMate Is SolidWorks.Interop.sldworks.Mate2 Then

                        swMate = SingleMate

                        typeOfMate = swMate.Type

                        Select Case typeOfMate

                            Case 0

                                Debug.Print("  Mate type: Coincident")

                            Case 1

                                Debug.Print("  Mate type: Concentric")

                            Case 2

                                Debug.Print("  Mate type: Perpendicular")

                            Case 3

                                Debug.Print("  Mate type: Parallel")

                            Case 4

                                Debug.Print("  Mate type: Tangent")

                            Case 5

                                Debug.Print("  Mate type: Distance")

                            Case 6

                                Debug.Print("  Mate type: Angle")

                            Case 7

                                Debug.Print("  Mate type: Unknown")

                            Case 8

                                Debug.Print("  Mate type: Symmetric")

                            Case 9

                                Debug.Print("  Mate type: CAM follower")

                            Case 10

                                Debug.Print("  Mate type: Gear")

                            Case 11

                                Debug.Print("  Mate type: Width")

                            Case 12

                                Debug.Print("  Mate type: Lock to sketch")

                            Case 13

                                Debug.Print("  Mate type: Rack pinion")

                            Case 14

                                Debug.Print("  Mate type: Max mates")

                            Case 15

                                Debug.Print("  Mate type: Path")

                            Case 16

                                Debug.Print("  Mate type: Lock")

                            Case 17

                                Debug.Print("  Mate type: Screw")

                            Case 18

                                Debug.Print("  Mate type: Linear coupler")

                            Case 19

                                Debug.Print("  Mate type: Universal joint")

                            Case 20

                                Debug.Print("  Mate type: Coordinate")

                            Case 21

                                Debug.Print("  Mate type: Slot")

                            Case 22

                                Debug.Print("  Mate type: Hinge") '

                                ' Add new mate types introduced after SolidWorks 2010 FCS here

                        End Select

                    End If

                    If TypeOf SingleMate Is SolidWorks.Interop.sldworks.MateInPlace Then

                        swMateInPlace = SingleMate

                        numMateEntities = swMateInPlace.GetMateEntityCount

                        For i = 0 To numMateEntities - 1

                            Debug.Print("  Mate component name: " & swMateInPlace.MateComponentName(i))

                            Debug.Print("    Type of mate inplace: " & swMateInPlace.MateEntityType(i))

                        Next i

                        Debug.Print("")

                    End If

                Next

            End If

            Debug.Print("")

        Next

 

    End Sub

 

    ''' <summary>

    ''' The SldWorks swApp variable is pre-assigned for you.

    ''' </summary>

    Public swApp As SldWorks

 

End Class



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 Example (VB.NET)
*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) 2010 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.