10-01-2018
03:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-01-2018
03:45 PM
Or maybe the issue is the code is attempting to rename an occurrence the same name as another occurrence... maybe something like this to catch that case.
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition i=1 FilePrefix = "Test_" 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences Dim oName As String oName = oOccurrence.Name oName2 = Left(oName, 1) oName3 = Left(oName, 3) oName4 = Mid(oName, 4) If oName2 = "-" Then oOccurrence.Name = FilePrefix & oName Else If oName3 <> FilePrefix Then Try oOccurrence.Name = FilePrefix & oName4 Catch 'error when name exists already oOccurrence.Name = FilePrefix & oName4 & ":" & i i=i+1 'increment counter End Try End If Next