This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
This macro will create child configuration where all the dimension will be set to average value based on the minimum and maximum values of the tolerance using SOLIDWORKS API.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
IfNot swModel IsNothingThenDim swFeat As SldWorks.Feature
Dim activeConfName AsString
activeConfName = swModel.ConfigurationManager.ActiveConfiguration.Name
swModel.ConfigurationManager.AddConfiguration "Average", "", "", 0, activeConfName, ""Set swFeat = swModel.FirstFeature
WhileNot swFeat IsNothingDim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Dim swDimTol As SldWorks.DimensionTolerance
Set swDispDim = swFeat.GetFirstDisplayDimension
WhileNot swDispDim IsNothingSet swDim = swDispDim.GetDimension2(0)
Set swDimTol = swDim.Tolerance
If swDimTol.Type <> swTolType_e.swTolNONE ThenDim averageVal AsDouble
averageVal = swDim.GetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, "")(0) + (swDimTol.GetMinValue + swDimTol.GetMaxValue) / 2
swDimTol.Type = swTolType_e.swTolNONE
swDim.SetSystemValue3 averageVal, swInConfigurationOpts_e.swThisConfiguration, ""EndIfSet swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
Wend
Set swFeat = swFeat.GetNextFeature
Wend
swModel.EditRebuild3
Else
MsgBox "Please open the model"EndIfEndSub
Notifications
Join session by SOLIDWORKS and PDM API expert Artem Taturevych at 3DEXPERIENCE World 2026 on Wednesday, Feb 4 at 08:30 AM CST to explore 10 essential macros for automating drawings, assemblies, custom properties, and more