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 VBA macro is useful for the users working with assemblies in the Large Design Review mode or when it is required to support configurations in eDrawings.
By default only active configuration is preserved for using the the Large Design Review mode and other configurations of the assembly cannot be activated:
This will allow to open all sub components in the Large Design Review mode and activate used configurations.
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swAssy As SldWorks.AssemblyDoc
Set swAssy = swApp.ActiveDoc
IfNot swAssy IsNothingThenDim vComps AsVariant
vComps = CollectSelectedComponents(swAssy)
If IsEmpty(vComps) Then
vComps = swAssy.GetComponents(False)
EndIfDim files AsObjectSet files = CollectFilesNeedDisplayMarks(vComps, swAssy.GetPathName)
ForEach filePath In files.Keys
Dim vConfNames AsVariant
vConfNames = files.item(filePath)
AddDisplayMarks CStr(filePath), vConfNames
NextElse
Err.Raise vbError, "", "Open assembly"EndIfEndSubFunction CollectSelectedComponents(model As SldWorks.ModelDoc2) AsVariantDim i AsIntegerDim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = model.SelectionManager
Dim swComps() As SldWorks.Component2
Dim isInit AsBooleanFor i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
If swSelMgr.GetSelectedObjectType3(i, -1) = swSelectType_e.swSelCOMPONENTS ThenDim swComp As SldWorks.Component2
Set swComp = swSelMgr.GetSelectedObject6(i, -1)
IfNot isInit Then
isInit = TrueReDim swComps(0)
ElseReDimPreserve swComps(UBound(swComps) + 1)
EndIfSet swComps(UBound(swComps)) = swComp
EndIfNextIf isInit Then
CollectSelectedComponents = swComps
Else
CollectSelectedComponents = Empty
EndIfEndFunctionFunction CollectFilesNeedDisplayMarks(comps AsVariant, rootDocPath AsString) AsObjectDim files AsObjectSet files = CreateObject("Scripting.Dictionary")
Dim i AsIntegerFor i = 0 To UBound(comps)
Dim swComp As SldWorks.Component2
Set swComp = comps(i)
Dim filePath AsString
filePath = ResolveReferencePath(rootDocPath, swComp.GetPathName())
If Dir(filePath) <> ""ThenDim refConfName AsString
refConfName = swComp.ReferencedConfiguration
Dim activeConfName AsString
activeConfName = swApp.GetActiveConfigurationName(swComp.GetPathName())
Dim confNames() AsStringIf LCase(refConfName) <> LCase(activeConfName) ThenIf files.Exists(LCase(filePath)) Then
confNames = files(LCase(filePath))
IfNot Contains(confNames, refConfName) ThenReDimPreserve confNames(UBound(confNames) + 1)
confNames(UBound(confNames)) = refConfName
files(LCase(filePath)) = confNames
EndIfElseReDim confNames(0)
confNames(0) = refConfName
files.Add LCase(filePath), confNames
EndIfEndIfElse
Debug.Print "Failed to resolve component " & swComp.Name2 & " path: " & filePath
EndIfNextSet CollectFilesNeedDisplayMarks = files
EndFunctionFunction Contains(arr() AsString, item AsString) AsBooleanDim i AsIntegerFor i = 0 To UBound(arr)
If LCase(arr(i)) = LCase(item) Then
Contains = TrueExitFunctionEndIfNext
Contains = FalseEndFunctionSub AddDisplayMarks(filePath AsString, confNames AsVariant)
Debug.Print "Adding display mark for " & filePath
Dim swModel As SldWorks.ModelDoc2
Dim swDocSpec As SldWorks.DocumentSpecification
Set swDocSpec = swApp.GetOpenDocSpec(filePath)
swDocSpec.LightWeight = False
swDocSpec.ViewOnly = False
swDocSpec.Silent = TrueSet swModel = swApp.OpenDoc7(swDocSpec)
IfNot swModel IsNothingThenSet swModel = swApp.ActivateDoc3(swModel.GetTitle(), False, swRebuildOnActivation_e.swDontRebuildActiveDoc, -1)
IfNot swModel IsNothingThenDim i AsIntegerFor i = 0 To UBound(confNames)
Dim swConf As SldWorks.Configuration
Set swConf = swModel.GetConfigurationByName(CStr(confNames(i)))
swConf.LargeDesignReviewMark = TrueNext
swModel.ForceRebuild3 False
swModel.Save3 swSaveAsOptions_e.swSaveAsOptions_Silent, 0, 0
swApp.CloseDoc swModel.GetTitle
Else
Debug.Print "Failed to activate document: " & filePath
EndIfElse
Debug.Print "Failed to open document: " & filePath
EndIfEndSubFunction ResolveReferencePath(rootDocPath AsString, refPath AsString) AsStringDim pathParts AsVariant
pathParts = Split(refPath, "\")
Dim rootFolder AsString
rootFolder = rootDocPath
rootFolder = Left(rootFolder, InStrRev(rootFolder, "\") - 1)
Dim i AsIntegerDim curRelPath AsStringFor i = UBound(pathParts) To 1 Step -1
curRelPath = pathParts(i) & IIf(curRelPath <> "", "\", "") & curRelPath
Dim path AsString
path = rootFolder & "\" & curRelPath
If Dir(path) <> ""Then
ResolveReferencePath = path
ExitFunctionEndIfNext
ResolveReferencePath = refPath
EndFunction
Alternative version of the macro will only process configurations of the active part or assembly and add the Display Data marks
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
IfNot swModel IsNothingThenIf swModel.GetType() = swDocumentTypes_e.swDocASSEMBLY Or swModel.GetType() = swDocumentTypes_e.swDocPART ThenDim vConfNames AsVariant
vConfNames = swModel.GetConfigurationNames
Dim i AsIntegerFor i = 0 To UBound(vConfNames)
Dim swConf As SldWorks.Configuration
Set swConf = swModel.GetConfigurationByName(CStr(vConfNames(i)))
swConf.LargeDesignReviewMark = TrueNext
swModel.ForceRebuild3 FalseElse
Err.Raise vbError, "", "Only assemblies and parts are supported"EndIfElse
Err.Raise vbError, "", "No files opened"EndIfEndSub