Hello,
I have VBA code that renames all browser nodes of top level assembly and its subassemblies. To rename browser node, I have to unsuppress the component, rename it and suppress it again. But for some reason, it is painfully slow - it takes almost 2 hours to complete. I have assembly with 373 referenced files, the assembly has all sorts of subcomponents (subassemblies, parts, content center parts, patterns...) and the code becomes slow when it tries to rename browser nodes of subassembly, which is medium sized and has other subassemblies.
Similar rule did run fast in older versions of Inventor where there has been level of detail and I did it from the main level of detail. But for Inv 2022 and 2023 it is very very slow. Do you have any tips how to make the code run faster?
Public RenamedFiles As Object
Sub Main()
Dim oDoc As Inventor.AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Set RenamedFiles = CreateObject("System.Collections.ArrayList")
Dim oOccurrence As ComponentOccurrence
Dim oAsmCompDef As Inventor.AssemblyComponentDefinition
Dim ListOfOccurrences As Object
Set ListOfOccurrences = CreateObject("System.Collections.ArrayList")
Set oAsmCompDef = oDoc.ComponentDefinition
Dim Item As Variant
RenameBrowserTree oAsmCompDef.Occurrences
MsgBox "Renaming finished in time: " & Time
End Sub
Sub RenameBrowserTree(Local_Occurrences As ComponentOccurrences)
Dim oLocal_Component_List As Object
Set oLocal_Component_List = CreateObject("System.Collections.ArrayList")
Dim Counter As Integer
Counter = 0
Dim TotalCounter As Integer
TotalCounter = 0
Dim Limit As Integer
Limit = 2000
Dim Local_CurrentIndex As Integer
Dim iVlastnost_nazev As String
Dim oKonec_nazvu As String
Dim oLocal_Occurrence As ComponentOccurrence
For Each oLocal_Occurrence In Local_Occurrences
oLocal_Component_List.Add oLocal_Occurrence.Name
Next
Dim Indexzadvojteckou As Integer
Dim OccurrenceIndex As Integer
Dim OccurrenceRenamed As Boolean
OccurrenceIndex = 0
Dim Local_Suppress As Boolean
Dim oSubDoc As Inventor.AssemblyDocument
For Each oLocal_Occurrence In Local_Occurrences
Local_Suppress = False
If oLocal_Occurrence.Suppressed = True Then
Local_Suppress = True
oLocal_Occurrence.Unsuppress
End If
If InStr(oLocal_Occurrence.Definition.Document.fullFilename, "\SOC\") = 0 Then 'If occurrence is content center part
iVlastnost_nazev = oLocal_Occurrence.Name
oLocal_Occurrence.Name = "RandomName"
oLocal_Occurrence.Name = iVlastnost_nazev
oLocal_Component_List(OccurrenceIndex) = oLocal_Occurrence.Name
Counter = Counter + 1
OccurrenceIndex = OccurrenceIndex + 1
If Local_Suppress = True Then
Local_Suppress = False
If oLocal_Occurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
OccurrenceRenamed = IsOccurrenceRenamed(oLocal_Occurrence.Definition.Document.fullFilename)
If OccurrenceRenamed = False Then
RenamedFiles.Add oLocal_Occurrence.Definition.Document.fullFilename
ThisApplication.SilentOperation = True
Set oSubDoc = ThisApplication.Documents.Open(oLocal_Occurrence.Definition.Document.fullFilename)
ThisApplication.SilentOperation = False
RenameBrowserTree oSubDoc.ComponentDefinition.Occurrences
oSubDoc.Save2
oSubDoc.Close
End If
End If
oLocal_Occurrence.Suppress
Else
If oLocal_Occurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
OccurrenceRenamed = IsOccurrenceRenamed(oLocal_Occurrence.Definition.Document.fullFilename)
If OccurrenceRenamed = False Then
RenamedFiles.Add oLocal_Occurrence.Definition.Document.fullFilename
ThisApplication.SilentOperation = True
Set oSubDoc = ThisApplication.Documents.Open(oLocal_Occurrence.Definition.Document.fullFilename)
ThisApplication.SilentOperation = False
RenameBrowserTree oSubDoc.ComponentDefinition.Occurrences
oSubDoc.Save2
oSubDoc.Close
End If
End If
End If
If Counter > Limit Then
TotalCounter = TotalCounter + Counter
'ThisApplication.ActiveDocument.PropertySets.Item("Inventor User Defined Properties").Item("Counter").Value = CStr(TotalCounter)
ThisApplication.ActiveDocument.Save2
Counter = 0
End If
Else 'Here, Occurrence is content center path
If Local_Suppress = True Then
Local_Suppress = False
oLocal_Occurrence.Suppress
End If
End If
Next
If IsObject(oDoc) Then
Else
End If
End Sub
Function IsOccurrenceRenamed(FileName As String) As Boolean
Dim Local_FileName As Variant
For Each Local_FileName In RenamedFiles
If Local_FileName = FileName Then
IsOccurrenceRenamed = True
Exit Function
End If
Next
IsOccurrenceRenamed = False
End Function
I also find Inventor 2023 slow in many things.
I believe the changes from LOD to Model States caused some changes in the way Inventor manages many things (suppress, properties, etc etc).
I believe that this will be "fixed" over time.... but ....that's only my opinion as a user.
Here...we are only users, we can give some help, and give an opinion, but we can«t do much about how the software works.
Contact product support and describe your issue, they need to know these things to take over and enhance the software.
Hello ccarreiras,
thank you for your reply. On official Autodesk website, it says: "Get answers fast from Autodesk support staff and product experts in the forums." with the link to this forum. So sooner or later this post will be seen by Autodesk support. Also, there are more older posts how to improve performance of VBA code or iLogic Rule, but only not for my issue.
But can you specify How can I contact Autodesk support? I browsed some support links and it looks like it is not intended to solve problems with performance of Inventor API, it is rather intended to more "common" problems like problems with printers..
Can't find what you're looking for? Ask the community or share your knowledge.