Add-in performance while Hiding select set

Add-in performance while Hiding select set

eyalad
Explorer Explorer
463 Views
5 Replies
Message 1 of 6

Add-in performance while Hiding select set

eyalad
Explorer
Explorer

Hi,

 

i have created an adding function that does some things... 

one of the operations is to hide everything that is selected (same as right clicking and toggeling visibility).

for some reason, when i select a large number of items, it takes a lot of time to hide them ass opposed to using right click...

 

my code looks like this (pseudo code):

-----------------

for each item in selectset

 item. visibility = false

next

------------

 

am i doing this the wrong way? 

can i make it somehow "smarter"

 

thanks,

 

Eyal

 

0 Likes
464 Views
5 Replies
Replies (5)
Message 2 of 6

dalton98
Collaborator
Collaborator

I don't know if theres a way to avoid using a for loop to change each individual one. You could disable screen updating and re-enable it when your finished. However, make sure you have a way of ensuring it comes back on.

On Error Resume Next
'On Error GoTo 7
ThisApplication.ScreenUpdating = False

'your code

ThisApplication.ScreenUpdating = True
0 Likes
Message 3 of 6

eyalad
Explorer
Explorer
Thank you very much.
I'll try
0 Likes
Message 4 of 6

tyler.warner
Advocate
Advocate

You may find some helpful info in this article as well, like putting that loop into a global transaction, etc.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 5 of 6

jjstr8
Collaborator
Collaborator

You're really at the mercy of how the API processes the visibility change.  There appears to be substantial processing going on with each item you change the visibility.  Here's a VBA snippet of hiding a selection set as a batch using the view representation.  I'm on 2019, so if your version has model states you'll have determine the equivalent.

 

Public Sub HideSelected()
    Dim objCollection As ObjectCollection
    Dim assemblyDoc As AssemblyDocument
    If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject Then
        Set assemblyDoc = ThisApplication.ActiveDocument
        Set objCollection = ThisApplication.TransientObjects.CreateObjectCollection
        If assemblyDoc.SelectSet.count > 0 Then
            For Each selection In assemblyDoc.SelectSet
                If TypeOf selection Is ComponentOccurrenceProxy Or TypeOf selection Is ComponentOccurrence Then
                    objCollection.Add selection
                End If
            Next
        assemblyDoc.ComponentDefinition.RepresentationsManager.ActiveDesignViewRepresentation.SetVisibilityOfOccurrences objCollection, False
        End If
    End If
End Sub
0 Likes
Message 6 of 6

JelteDeJong
Mentor
Mentor

You might want to have a look at these articles:

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes