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
User can change the solving options (rigid or flexible) for assembly components using components options page or toolbar command. This is however only limited for one component at a time.
This VBA macro allows to set either rigid or solved options for all selected components as one command using SOLIDWORKS API.
Specify the option as follows:
Const SET_FLEXIBLE AsBoolean = True'True - set to flexible, False - set to Rigid
Const SET_FLEXIBLE AsBoolean = TrueDim swApp As SldWorks.SldWorks
Dim swAssy As SldWorks.AssemblyDoc
Sub main()
Set swApp = Application.SldWorks
Set swAssy = swApp.ActiveDoc
IfNot swAssy IsNothingThenDim vComps AsVariant
vComps = GetSelectedAssemblyComponents
IfNot IsEmpty(vComps) ThenDim solveOpts As swComponentSolvingOption_e
If SET_FLEXIBLE Then
solveOpts = swComponentFlexibleSolving
Else
solveOpts = swComponentRigidSolving
EndIfDim i AsIntegerFor i = 0 To UBound(vComps)
Dim swComp As SldWorks.Component2
Set swComp = vComps(i)
SetSolvingFlag swComp, solveOpts
NextElse
MsgBox "Please select assembly components"EndIfElse
MsgBox "Please open assembly"EndIfEndSubFunction GetSelectedAssemblyComponents() AsVariantDim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = swAssy.SelectionManager
Dim isInit AsBoolean
isInit = FalseDim swComps() As SldWorks.Component2
Dim i AsIntegerFor i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
Dim swComp As SldWorks.Component2
Set swComp = swSelMgr.GetSelectedObjectsComponent2(i)
Const ASM_EXT AsString = ".sldasm"Dim ext AsString
ext = Right(swComp.GetPathName(), Len(ASM_EXT))
If LCase(ext) = LCase(ASM_EXT) ThenIf isInit ThenReDimPreserve swComps(UBound(swComps) + 1)
ElseReDim swComps(0)
isInit = TrueEndIfSet swComps(UBound(swComps)) = swComp
EndIfNextIf isInit Then
GetSelectedAssemblyComponents = swComps
Else
GetSelectedAssemblyComponents = Empty
EndIfEndFunctionSub SetSolvingFlag(comp As SldWorks.Component2, solveOpts As swComponentSolvingOption_e)
comp.Select4 False, Nothing, FalseDim suppOpts AsLongDim isVisible AsBooleanDim exlFromBom AsBooleanDim isEnv AsBooleanDim useNamedConf AsBooleanDim refConfName AsString
suppOpts = comp.GetSuppression()
isVisible = comp.Visible
exlFromBom = comp.ExcludeFromBOM
isEnv = comp.IsEnvelope
useNamedConf = False
refConfName = ""
swAssy.CompConfigProperties5 suppOpts, solveOpts, isVisible, useNamedConf, refConfName, exlFromBom, isEnv
EndSub
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