Attributes - very low efficiency

Attributes - very low efficiency

pawel_watroba
Explorer Explorer
244 Views
4 Replies
Message 1 of 5

Attributes - very low efficiency

pawel_watroba
Explorer
Explorer

Hello,

 

I use Inventor 2024 and i would like to set about 20 000 attributes in part model. Unfortunately, setting attributes i very slow (about 1sec per one attribute). Anyone know is possible to speed up it?

 

Thanks,

Paweł

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

ryan.rittenhouse
Advocate
Advocate

Can you please post an example of what attributes you are setting and a code snippet of how you are setting them so I have a better handle on why it's being slow?

If this solved your problem, or answered your question, please click Accept Solution.
0 Likes
Message 3 of 5

pawel_watroba
Explorer
Explorer

The first step is import from step file model with surfaces to a part document. There is above 20 000 surfaces. 

 

The next step is setting attributes to each surfaces, belowe code of this step:

 

oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim iden As String
For Each surf As PartFeature In oCompDef.Features
    iden = surf.Name.Substring(surf.Name.Length - 3)
    surf.Name = iden
    surf.AttributeSets.Add("Weld_SURF-" + iden)
Next

 Each step in the loop takes about 1s... 

 

 

0 Likes
Message 4 of 5

cadconfigurator
Participant
Participant

Hi @pawel_watroba The only solution is to create a Collection, i could not test it on 20000 surfacebodies, but this may help

Dim InvApp As Inventor.Application = ThisApplication
Dim oDoc As PartDocument = InvApp.ActiveDocument
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition

Dim surfCollection As New Collection
For Each surf As PartFeature In oCompDef.Features
    surfCollection.Add (surf)
Next

Dim iden As String
' Apply changes
For Each surf In surfCollection
    iden = surf.Name.Substring(surf.Name.Length - 3)
    surf.Name = iden
    surf.AttributeSets.Add ("Weld_SURF-" & iden)
Next
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Since that one iteration is doing multiple things (accessing Property values, String manipulations, PartFeature renaming, then AttributeSet creation), it is most likely not the task of adding an AttributeSet to each PartFeature that is taking the bulk of the time.  It is most likely the PartFeature renaming part that is the most time consuming.  I'm pretty sure the act of changing a feature's name will cause multiple other 'background process' to get triggered and processed.  As for possible strategies for reducing that processing time, I have a couple ideas, but not sure how effective they will be for you in this situation.  The type of document (part or assembly) you are dealing with may also play an important role.

  • If it's an assembly, then one thing you may want to try is turning the DeferUpdate setting on.  That setting is in the Application Options, on the Assembly tab, right at the top.  When that setting is turned on (checkbox checked), then some types of changes will not be visually seen immediately when they would normally happen, but will wait until you explicitly click the Update button, then things will visually update.  This setting can also be reached by code with the AssemblyOptions.DeferUpdate property, which can be reached from the Application.AssemblyOptions property.  However, you may want to set that back the way it was when your process is done, even if an error interrupts the process.
  • You can try setting the Application.ScreenUpdating property's value to False, temporarily while your process is working, then back to True when done.  Again, this one is dangerous to leave off if an error interrupts your code, so you may need to incorporate a Try...Catch...Finally...End Try statement into your code, and put the 'risky' part on the 'Try' side, and the code to turn that setting back on in the Finally part, so that it will always get executed, even if an error happens.
  • The Application.SilentOperation property is another similar type of setting, which will help eliminate any Inventor dialogs from popping-up while your code is working, but that does not seem like it would help much in this exact situation.

There maybe a couple other little tips like that floating around also, but those are the ones that immediately came to mind.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes