Q:
I want to set the Visibility flag on Occurrences in an Assembly. What is the most efficient way to do this?"
A:
Following are two approaches to test the time taken to set the visibility of all the occurrences.
1) The IndividualUpdate() function sets the visible property on each occurrence individually.
2) The SelectionUpdate() function adds the occurrence to the selection set, then executes a command that sets the visibility on the selected items.
It is recommended that the technique employed in 'SelectionUpdate()' function is used when setting the occurrence visibility flags in large assemblies. It is only valid when the document is open visible and active in Inventor.
Sub IndividualUpdate(ByVal app As Inventor.Application)
Dim doc As AssemblyDocument
doc = app.ActiveDocument
Dim compDef As AssemblyComponentDefinition
compDef = doc.ComponentDefinition
Dim StartTime As Date = Now
Dim occ As ComponentOccurrence
Dim i As Long
For i = 1 To compDef.Occurrences.Count
occ = compDef.Occurrences(i)
occ.Visible = False
Next
Call doc.Update()
Debug.Print(
"Elapsed Time(sec): " +
DateDiff("s", StartTime, Now).ToString())
End Sub
Sub SelectionUpdate(ByVal app As Inventor.Application)
Dim doc As AssemblyDocument
doc = app.ActiveDocument
Dim compDef As AssemblyComponentDefinition
compDef = doc.ComponentDefinition
Dim StartTime As Date = Now
Dim i As Long
For i = 1 To compDef.Occurrences.Count
doc.SelectSet.Select(compDef.Occurrences(i))
Next
Dim ctrlDef As ControlDefinition
ctrlDef = app.CommandManager.ControlDefinitions.Item(
"AssemblyVisibilityCtxCmd")
Call ctrlDef.Execute()
Call doc.Update()
Debug.Print(
"Elapsed Time(sec): " +
DateDiff("s", StartTime, Now).ToString())
End Sub