Hide Table of Contents

SOLIDWORKS API Help

Create a Mate Controller Example (VB.NET)

This example shows how to create a Mate Controller in an assembly.

'======================================================================================

' Preconditions: Open an assembly document that contains a mechanical slot feature

' with a slot mate that has one of these constraints:

'    - Distance Along Slot

'    - Percent Along Slot

'

' Postconditions:

' 1. Mate Controller (Position 3) is added to the FeatureManager design tree.

' 2. Inspect the graphics area.

'
' NOTE: Because the model is used elsewhere, do not save changes.
'---------------------------------------------------------------------------

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System.Runtime.InteropServices

Imports System

 

Partial Class SolidWorksMacro

     

    Dim Part As ModelDoc2

    Dim Assem As AssemblyDoc

    Dim featMgr As FeatureManager

    Dim boolstatus As Boolean

    Dim myModelView As Object

    Dim var As Object

    Dim mateControllerObj As MateControllerFeatureData

    Dim mcObj2 As MateControllerFeatureData

    Dim mateContFeat As Feature

    Dim position2ValArr(0) As Double

    Dim position3ValArr(0) As Double

    Dim var1 As Object

    Dim position2ValArr2(0) As Double

    Dim position3ValArr2(0) As Double

 

    Function ObjectArrayToDispatchWrapperArray(ByVal Objects As Object()) As DispatchWrapper()

        Dim ArraySize As Integer

        ArraySize = Objects.GetUpperBound(0)

        Dim d(ArraySize) As DispatchWrapper

        Dim ArrayIndex As Integer

        For ArrayIndex = 0 To ArraySize

            d(ArrayIndex) = New DispatchWrapper(Objects(ArrayIndex))

        Next

        Return d

    End Function

 

    Sub main()

 

        Part = swApp.ActiveDoc

        Assem = Part

 

        myModelView = Part.ActiveView

        myModelView.FrameState = swWindowState_e.swWindowMaximized

        Part.ClearSelection2(True)

 

        boolstatus = Assem.IsSupportedMatesAvailable

 

        var = Assem.CollectAllSupportiveMates

 

        featMgr = Part.FeatureManager

 

        mateControllerObj = featMgr.CreateDefinition(swFeatureNameID_e.swFmMateController)

 

        Dim dArray() As DispatchWrapper

        dArray = ObjectArrayToDispatchWrapperArray(var)

 

        Call mateControllerObj.Initialize(dArray)

 

        mateControllerObj.AddNewPosition("Position1")

        mateControllerObj.AddNewPosition("Position2")

        mateControllerObj.AddNewPosition("Position3")

 

        position2ValArr(0) = 0.0375

        Call mateControllerObj.SetValues("Position2", position2ValArr)

 

        position3ValArr(0) = 0.0625

        Call mateControllerObj.SetValues("Position3", position3ValArr)

 

        mateContFeat = featMgr.CreateFeature(mateControllerObj)

 

        mcObj2 = mateContFeat.GetDefinition()

 

        var1 = mcObj2.Mates

 

        position2ValArr2(0) = 0.015

        Call mcObj2.SetValues("Position2", position2ValArr2)

 

        position3ValArr2(0) = 0.085

        Call mcObj2.SetValues("Position3", position3ValArr2)

 

        mateContFeat.ModifyDefinition(mcObj2, Part, Nothing)

 

    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:   Create a Mate Controller 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) 2024 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.