Rename all occurrences and suboccurrences names in browser tree error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am renaming all occurrences and suboccurrences names by this VBA macro, it recursively renames all occurrences.
Sub Main()
Call RenameBrowserTree_Call
End Sub
Sub RenameBrowserTree_Call()
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
ThisApplication.ScreenUpdating = True
Exit Sub
End If
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
Dim oOccurrence As ComponentOccurrence
Dim oSubOccurrence As ComponentOccurrence
Dim oPuvodniuroven As String
Set oAsmCompDef = oAsmDoc.ComponentDefinition
Call RenameBrowserTree(oAsmCompDef.Occurrences)
ThisApplication.ScreenUpdating = True
End Sub
Sub RenameBrowserTree(Occurrences As ComponentOccurrences)
Dim Pozice_podtrzitek As String
Dim Pozice_dvojtecky As String
Dim oKonec_nazvu As String
Dim oOccDocument As Inventor.Document
For Each oOccurrence In Occurrences
Pozice_podtrzitek = InStr(oOccurrence.Name, "__")
If Pozice_podtrzitek <> 0 Then
Pozice_dvojtecky = InStr(oOccurrence.Name, ":")
If Pozice_dvojtecky <> 0 Then
oKonec_nazvu = Right(oOccurrence.Name, Len(oOccurrence.Name) - Pozice_dvojtecky + 1)
Else
oKonec_nazvu = ""
End If
'On Error Resume Next
'Err.Clear
oOccurrence.Definition.Document.Update
oOccurrence.Name = Left(oOccurrence.Name, Pozice_podtrzitek - 1) & oKonec_nazvu
'If Err.Number <> 0 Then
' Times_to_rename = Times_to_rename + 1
' oOccurrence.Definition.Document.Update
' oOccurrence.Parent.Document.Open
' oOccurrence.Name = Left(oOccurrence.Name, Pozice_podtrzitek - 1) & oKonec_nazvu
'End If
End If
If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
Call RenameBrowserTree(oOccurrence.SubOccurrences) 'Rekurzivní volání - volá, dokud se nedostane na nejnižší úroveň komponent
End If
Next
End Sub
But when I have Top level assembly, and in there I have Assembly A with parts, then I have Assembly B, which contains Assembly A and other files, VBA macro throws this error message: Run-time error: Method of Name of object ComponentOccurrenceProxy failed.
It does this when trying to rename Assembly A in context of Assembly B (note that Assembly A has been renamed in Top-level Assembly). Funny thing is that when I open document of Assembly B and run there the same macro, it works. Also I noticed that it has no problem with runing newly created Inventor 2022 files, but it throws error when the files are originally created in INV 2020 and then migrated to INV 2022.
Please, do you have any idea how to solve this? What this could be caused by?
Thank you 🙂