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