我有catia v5的代码,它工作正常。唯一的问题是,当您执行“selection1.Add”时,它会遍历文档的所有组件,无论它们是否可见,这使得执行此行时代码变慢。有人有改进建议吗?
我考虑过仅使用可见产品中的可见部分来过滤“invertedSelection”,也就是说,如果产品可见,则查找该产品中的可见部分。如果此可见产品中有可见部分,请将它们添加到“InvertedSelection”。如果看不到产品,请勿寻找产品内部的零件。
子 CATMain()
调暗选择 1 作为选择 设置选择 1 = CATIA.ActiveDocument.Selection
将 visPropertySet1 调暗为 VisPropertySet 设置 visPropertySet1 = Selection1.VisProperties
如果选择1.Count > 0 则
' Retrieve the Groups collection
Dim cGroups As Object
Set cGroups = CATIA.ActiveDocument.product.GetTechnologicalObject("Groups")
' Create a group with selected products
Dim oGroup As Group
Set oGroup = cGroups.AddFromSel
' Fill the selection with the inverted group
oGroup.FillSelWithInvert
visPropertySet1.SetShow 1
' Store the inverted selection in a collection
Dim invertedSelection As New Collection
Dim i As Integer
For i = 1 To selection1.Count
invertedSelection.Add selection1.Item(i).Value
Next i
' Clear the selection
selection1.Clear
UserForm1.Show
' Code will continue here while the UserForm is open
Do While UserForm1.Visible
DoEvents
Loop
' Make the components in the inverted selection visible again
For i = 1 To invertedSelection.Count
selection1.Add invertedSelection.Item(i)
Next i
Dim visPropertySet2 As VisPropertySet
Set visPropertySet2 = selection1.VisProperties
visPropertySet2.SetShow 0
selection1.Clear
其他
MsgBox "Nenhum componente selecionado", vbExclamation, "Isolate Components"
Exit Sub
结束如果
结束子
为了提高选择操作的性能,您可以关闭所选元素的突出显示。
'switch highlighting off
Catia.HSOSynchronized = false
'do stuff with the selection
'turn highlighting on (e.g. end of your code)
Catia.HSOSynchronized = true