How to perform an action on multiple parts as a single action/call, instead of separate actions/calls

How to perform an action on multiple parts as a single action/call, instead of separate actions/calls

Majjek
Advocate Advocate
322 Views
4 Replies
Message 1 of 5

How to perform an action on multiple parts as a single action/call, instead of separate actions/calls

Majjek
Advocate
Advocate

Hello,

 

When I have to do an action on multiple parts in an assembly via API, let's say suppressing a component, what I now do is something like this:

 

For Each oOcc in oComp.Occurrences
    If oOcc.Name = "Something" Then
        oOcc.Suppress
    Else
        oOcc.Unsuppress
    End If
Next

 

But when I would do this manually in Inventor, I would just select all the required occurrences and the Right click and choose Suppress.

Now it performs the Suppress action on all occurrences at once, instead of suppressing one, then the next etc.

The performance of the 'batch' action is a lot faster.

 

Is there a way to do a 'batch' action from the API?

I know it should also be possible to select all required occurrences, and then use the commandmanager to execute, but it seems a bit like a work around and for some commands, the actual command requires some input/prompts.

 

Thanks in advance.

 

0 Likes
323 Views
4 Replies
Replies (4)
Message 2 of 5

FINET_Laurent
Advisor
Advisor

Hi @Majjek,

 

Here would be the code with the command manager, just in case :

Dim doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument

Dim s As Inventor.SelectSet = doc.SelectSet
s.Clear

For Each o As Inventor.ComponentOccurrence In doc.ComponentDefinition.Occurrences
	If o.Name = "something" Then s.Select(o)

Next

ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyCompSuppressionCtxCmd").Execute

 

Here is also a topic about this debate, I made few months ago : Re: Switch Design views representation for multiple occurences at once - Autodesk Community - Invent...

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 5

Majjek
Advocate
Advocate

Thanks for your response.

 

Your topic addresses the same issue I'm facing.

I didn't know of the existence of the PostPriveEvent method.

I will follow your topic.

Message 4 of 5

A.Acheson
Mentor
Mentor

Hi @Majjek 

Have you tried wrapping the suppress rule in a transaction?. This should cut down on time it takes to record a single transaction for each suppress. I looked at the documentation and there is no method for suppress multiple occurrences simultaneously. Likewise when using command via control definition you cannot fire the command on multiple occurrences instead you must select each one in turn. 

Maybe their is savings in the way you get to your occurrences. Also I see in your below rule your suppressing and unsupressing in the same loop but when you select via UI your only doing one operation suppressing or unsupressing but not both. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 5

Majjek
Advocate
Advocate

Hi Alan,

 

I've tried using transactions, but it only slightly improves performance.

 

Suppress with Transaction took: 2250milliseconds
Unsuppress with Transaction took: 1641milliseconds
Suppress without Transaction took: 2359milliseconds
Unsuppress without Transaction took: 1938milliseconds
Suppress commandmanager took: 1031milliseconds
Unsuppress commandmanager took: 1172milliseconds

 

As far as I can see, is that although it groups the separate suppress actions, it stills 'calculates' them 1 by 1.

 

The example I gave was just a dummy code, so not a real example of my code.

0 Likes