|
经典图书
选中轻化或压缩文件时,选中会丢失,复制下面的子函数替换即可。
Private Sub HandleComponentSuppression()
Dim swSelMgr As SldWorks.SelectionMgr
Dim selCount As Long
Dim compIDs() As String
Dim i As Long
Set swSelMgr = swModel.SelectionManager
selCount = swSelMgr.GetSelectedObjectCount2(-1)
' 保存所有选中组件的ID
ReDim compIDs(selCount - 1)
For i = 1 To selCount
Dim currentComp As SldWorks.Component2
Set currentComp = swSelMgr.GetSelectedObjectsComponent4(i, -1)
If Not currentComp Is Nothing Then
compIDs(i - 1) = currentComp.GetSelectByIDString()
End If
Next
' 处理每个组件的抑制状态
For i = 0 To UBound(compIDs)
swModel.ClearSelection2 True
If swModel.Extension.SelectByID2(compIDs(i), "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) Then
Set currentComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
' 处理父装配体链
Dim parentComp As SldWorks.Component2
Do
Set parentComp = currentComp.GetParent
If parentComp Is Nothing Then Exit Do
Select Case parentComp.GetSuppression
Case 0, 1 ' 压缩或轻化
parentComp.SetSuppression2 2 ' 完全解析
End Select
Set currentComp = parentComp
Loop
' 处理当前组件
Set currentComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
Select Case currentComp.GetSuppression
Case 0, 1 ' 压缩或轻化
currentComp.SetSuppression2 2 ' 完全解析
End Select
End If
Next
' 恢复所有选择
swModel.ClearSelection2 True
For i = 0 To UBound(compIDs)
swModel.Extension.SelectByID2 compIDs(i), "COMPONENT", 0, 0, 0, True, 0, Nothing, 0
Next
' 统一重建
swModelDocExt.Rebuild swRebuildOptions_e.swRebuildAll
End Sub |
|