跳到主要内容

打开绘图视图引用文档的VBA宏

这个VBA宏执行类似于打开装配体命令的操作,但还会激活与绘图视图关联的引用显示状态。

打开装配体命令

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

If Not swModel Is Nothing Then

Dim swSelMgr As SldWorks.SelectionMgr

Set swSelMgr = swModel.SelectionManager

Dim swView As SldWorks.View

Set swView = swSelMgr.GetSelectedObject6(1, -1)

If Not swView Is Nothing Then

Dim swRefDoc As SldWorks.ModelDoc2
Set swRefDoc = swView.ReferencedDocument

If swRefDoc Is Nothing Then
Err.Raise vbError, "", "绘图视图模型未加载"
End If

swRefDoc.ShowConfiguration2 swView.ReferencedConfiguration

Dim swConf As SldWorks.Configuration
Set swConf = swRefDoc.GetConfigurationByName(swView.ReferencedConfiguration)

swConf.ApplyDisplayState swView.DisplayState

swRefDoc.Visible = True

Else
Err.Raise vbError, "", "请选择绘图视图"
End If

Else
Err.Raise vbError, "", "没有活动文档"
End If

End Sub