- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am migrating my current add in that was developed for 2020 and 2021 to version 2025. As expected some issues have reared their head in this process. This one in particular is not allowing me to debug the failure of the method.
We have configurable assemblies. To start a new assembly I have a bit of code that creates a copy of an existing configurable assembly, using system.io.file.copy same as copying in windows explorer. This copies all of the files. The assembly and the parts and subassemblies in the main assembly. After the copy the files are renamed to make them unique. Once this is completed I need to iterate thru the assembly to replace the file references for all of the components, parts and subassemblies and parts in the subassemblies. . . to make the assembly point to the new components.
Below is the code for updating the assembly component references to point to the new files. This is a recursive sub when it comes to subassemblies.
Private Sub UpdateAssemblyPartReferences(asmDef As Inventor.AssemblyComponentDefinition, level As Integer)
Dim increment As Double
increment = Math.Floor(100 / asmDef.Occurrences.Count)
ProgressBar2.Value = ProgressBar2.Minimum
For Each CompOcc As Inventor.ComponentOccurrence In asmDef.Occurrences
Dim compDef As Inventor.ComponentDefinition
compDef = CompOcc.Definition
Dim compDoc As Inventor.Document
compDoc = compDef.Document
If compDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
Dim ReplacedAssemRef As Boolean
ReplacedAssemRef = replaceFileRef(CompOcc)
If ReplacedAssemRef Then 'replace the subassembly subcomponents if the subassembly reference was replaced.
Dim AsmDoc As Inventor.AssemblyDocument
'redefine the compdoc here after the compOcc has been redefined
compDoc = CompOcc.Definition.Document
'AsmDoc = ThisApplication.Documents.Open(compDoc.File.FullFileName)
AsmDoc = compDoc
Dim subAssemCompDef As Inventor.AssemblyComponentDefinition
subAssemCompDef = AsmDoc.ComponentDefinition
UpdateAssemblyPartReferences(subAssemCompDef, 2)
'AsmDoc.Close(False)
End If
ElseIf compDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
replaceFileRef(CompOcc)
End If
If level = 1 Then
ProgressBarIncrement(ProgressBar1, increment)
Me.Refresh()
Else
ProgressBarIncrement(ProgressBar2, increment)
Me.Refresh()
End If
Next
End Sub
Here is the code that actually replaces the file references.
Private Function replaceFileRef(CompOcc As Inventor.ComponentOccurrence) As Boolean ' will return true if the componenet file reference was replaced. Will return false otherwise.
Dim FileDisc As Inventor.FileDescriptor
FileDisc = CompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor
Dim curFileName As String
Dim newFileName As String
curFileName = FileDisc.FullFileName
Dim SerialNumStr As String
SerialNumStr = SerialNum & "_"
If InStr(curFileName, "\SO-") > 0 Then
Dim curFileNameRelPath As String = curFileName.Substring(ConfigPath.Length)
newFileName = vesselPath & curFileNameRelPath.Replace("\SO-", "\" & SerialNumStr)
If System.IO.File.Exists(newFileName) Then
Try
FileDisc.ReplaceReference(newFileName)
If FileDisc.FullFileName = newFileName Then
Return True
Else
MsgBox(FileDisc.FullFileName & " was not changed to " & newFileName, vbOKOnly, "Error replacing file")
Return False
End If
Catch ex As Exception
MsgBox(FileDisc.FullFileName & ": " & ex.Message & " : " & ex.StackTrace, vbOKOnly, "Error replacing file")
End Try
Exit Function
End If
End If
Return False
End Function
The issue is that in 2025 the top level components file references are successfully replaced. However the components in the subassemblies are not successfully replaced.
The line FileDisc.ReplaceReference(newFileName) is being ran. No error is being thrown. But the file reference is not replaced on subassembly components only. Top level assembly components are being appropriately replaced.
Any insight as to why this is happening in 2025 and it worked fine in 2021.
Thanks in advance.
Solved! Go to Solution.