> Change Dimensions of Gear Mate Example (VBA)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show Table of Contents

Change Dimensions of Gear Mate Example (VBA)

This example shows how to change the dimensions of a gear mate.

 

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

'

' Preconditions:

'          (1) Assembly document is open.

'          (2) GearMate1 exists.

'

' Postconditions:

'          (1) Dimensions of gear mate are halved.

'          (2) Assembly is rebuilt.

'

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

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swMate As SldWorks.Mate2

Dim swFeature As SldWorks.Feature

Dim swModelDocExt As SldWorks.ModelDocExtension

Dim swSelMgr As SldWorks.SelectionMgr

Dim boolstatus As Boolean

Dim longstatus As Long

Dim longwarnings As Long

Dim swDispDim_1 As SldWorks.DisplayDimension

Dim swDispDim_2 As SldWorks.DisplayDimension

Dim swDim_1 As SldWorks.Dimension

Dim swDim_2 As SldWorks.Dimension

Dim dimValue_1 As Variant

Dim dimValue_2 As Variant

 

Sub main()

 

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swModelDocExt = swModel.Extension

    Set swSelMgr = swModel.SelectionManager

    swModel.ShowFeatureDimensions

  

    ' Select the gear mate

    boolstatus = swModelDocExt.SelectByID2("GearMate1", "MATE", 0, 0, 0, False, 0, Nothing, swSelectOptionDefault)

    Set swFeature = swSelMgr.GetSelectedObject5(1)

    Set swMate = swFeature.GetSpecificFeature2

    

    ' Mate2::DisplayDimension2 is a property

    ' that requires an index argument.

    

    ' For a distance mate, there is only one display dimension.

    ' Therefore, Mate2::DisplayDimension2(0) gives one display dimension.

    

    ' For a gear mate, there are two display dimensions

    ' Therefore, Mate2::DisplayDimension2(0) and

    ' Mate2::DisplayDimension2(1) give two display dimensions.

    

    ' Get the gear mates' display dimensions

    Set swDispDim_1 = swMate.DisplayDimension2(0)

    Set swDispDim_2 = swMate.DisplayDimension2(1)

    

    ' Get the dimensions

    Set swDim_1 = swDispDim_1.GetDimension

    Set swDim_2 = swDispDim_2.GetDimension

    

    ' Get the value of dimensions

    dimValue_1 = swDim_1.GetSystemValue3(swThisConfiguration, Empty)

    dimValue_2 = swDim_2.GetSystemValue3(swThisConfiguration, Empty)

    

    

    ' Half the values of dimensions

    dimValue_1(0) = dimValue_1(0) / 2

    dimValue_2(0) = dimValue_2(0) / 2

    longstatus = swDim_1.SetSystemValue3(dimValue_1(0), swSetValue_InThisConfiguration, Empty)

    longstatus = swDim_2.SetSystemValue3(dimValue_2(0), swSetValue_InThisConfiguration, Empty)

    

    swModel.EditRebuild3

    

End Sub



Related SolidWorks Forum Content

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:   Change Dimensions of Gear Mate Example (VBA)
*Comment:  
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

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document 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.