How can i speed up adding parts to an assembly?

How can i speed up adding parts to an assembly?

mitcham_boy
Enthusiast Enthusiast
2,311 Views
3 Replies
Message 1 of 4

How can i speed up adding parts to an assembly?

mitcham_boy
Enthusiast
Enthusiast

Hi

 

I have a VB code that gets an instance of inventor.  It creates a new assembly and then starts adding parts to it.  The code works fine and is reliable but I am suprised by how slow the process is.. the process is as follows

 

'psuedo code...

 

do

 

myAssembly.ComponentDefinition.Occurrences.Add(my_component_file, my_position)  'add my next occurrence to the assembly

 

myOccurrence.Transformation = my_position ' move the occurrence to a new position in assembly space.

 

With myOccurrence.Definition  'go thru the occurrence and change its dimensions

   ForEach p In.Parameters

      If p.Name = my_parameter_name Then p.Value = my_parameter_value

 

   Next

 

EndWith

 

loop until my_last_component

 

 

...I notice that the green progress bar is frequently on with messages in the Inventor statusbar such as "Executing update component" and "Executing change component position".

 

I wonder is Inventor performing many read/write operations which is causing the slow performance?  Perhaps it is updating files after each of my 3 operations in the loop... and if so is there a way i can achieve this faster such as delaying read/write until after all three operations have been performed or until all occurrences have been added??

 

Any tips appreciated.

Thanks.

Dan

(Belfast, Inventor 2013)

0 Likes
Accepted solutions (1)
2,312 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

 

The following VBA code demonstrates some of the ways you can optimize your Inventor plugins:

 

 

Sub PerformanceIncrease()

    Dim Invapp As Inventor.Application
    Set Invapp = ThisApplication

    '' Turn off user interaction so that inventor can focus on your API calls exclusively
    Invapp.UserInterfaceManager.UserInteractionDisabled = True
    
    '' Turn off screenupdating to speed up performance
    Invapp.ScreenUpdating = False
    
    '' Set Defer updates to true and force an update when you're finished with your API commands
    '' This can be done on drawings and sketches as well
    Invapp.AssemblyOptions.DeferUpdate = True
    
    '' Create the document invisible
    Dim oAssDoc As Inventor.AssemblyDocument
    Set oAssDoc = Invapp.Documents.Add( _
        Inventor.DocumentTypeEnum.kAssemblyDocumentObject, , True)
        
    ''Wrap your command into a global transaction so only one undo point is created.
    Dim oTrans As Inventor.Transaction
    
    Set oTrans = Invapp.TransactionManager.StartGlobalTransaction(oAssDoc, _
        "My API Calls")
        
    '' perform your functions here
    
    '' Be sure to end a global transaction when you are finished
    oTrans.End
        
    '' Wrap up
    Invapp.ScreenUpdating = True
    Invapp.UserInterfaceManager.UserInteractionDisabled = False
    
    '' Make the assembly document visible
    Call oAssDoc.Views.Add
    Call oAssDoc.Update
    Invapp.AssemblyOptions.DeferUpdate = False
    
End Sub

 

 

 

Message 3 of 4

mitcham_boy
Enthusiast
Enthusiast
Robert thanks for these tips - some of them i have in place already like the invisible document and screenupdating - i'm going to add the others and see what happens !
0 Likes
Message 4 of 4

maxim.teleguz
Advocate
Advocate

here is one for the books that works for some reason really well in 2022 you dont need to set it to false either. 

Imports System.Windows.Forms
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System
AddReference "System.Drawing.dll"

ThisApplication.AssemblyOptions.EnableAssemblyExpress = True
ThisApplication.ScreenUpdating = True

SendKeys.SendWait("{ESC}")
AppActivate(ThisApplication.Caption)

 

0 Likes