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 performs similar operation to Open assembly command on the selected SOLIDWORKS drawing view, but also activates the referenced display state associated with the drawing view.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
IfNot swModel IsNothingThenDim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = swModel.SelectionManager
Dim swView As SldWorks.View
Set swView = swSelMgr.GetSelectedObject6(1, -1)
IfNot swView IsNothingThenDim swRefDoc As SldWorks.ModelDoc2
Set swRefDoc = swView.ReferencedDocument
If swRefDoc IsNothingThen
Err.Raise vbError, "", "Drawing view model is not loaded"EndIf
swRefDoc.ShowConfiguration2 swView.ReferencedConfiguration
Dim swConf As SldWorks.Configuration
Set swConf = swRefDoc.GetConfigurationByName(swView.ReferencedConfiguration)
swConf.ApplyDisplayState swView.DisplayState
swRefDoc.Visible = TrueElse
Err.Raise vbError, "", "Select drawing view"EndIfElse
Err.Raise vbError, "", "No active documents"EndIfEndSub
Notifications
Join session by SOLIDWORKS and PDM API expret Artem Taturevych at 3DEXPERIENCE World 2025 on Feb 26 at 08:30 AM CST to explore 10 essential macros for automating drawings, assemblies, custom properties, and more