Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to change the filenames without losing references, and when I have one assembly within another assembly, the file references get lost.
On line 22, if its parent is different from 'asmDoc,' take its parent to set the reference, but I am not able to access the parent from oDoc.
'set a reference to the assembly component definintion
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Inventor.Document
'Store referenced documents properties
For Each oDoc In asmDoc.AllReferencedDocuments
Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
Dim fileType As String = System.IO.Path.GetExtension(oDoc.FullFileName)
Dim DrawCode As String
DrawCode = FindObject(fileName, fileType)
If DrawCode Is Nothing Then Continue For
'iProperties.Value(oDoc.DisplayName, "Custom", "Codigo Antigo") = fileName
Dim directoryPath As String = System.IO.Path.GetDirectoryName(oDoc.FullFileName)
Dim newFilePath As String = System.IO.Path.Combine(directoryPath, DrawCode)
Dim oldFilePath As String = oDoc.FullFileName
If oDoc.Parent.Name <> asmDoc.DisplayName
' Renomeia o arquivo
Try
oDoc.SaveAs(newFilePath, False)
asmDoc.File.ReferencedFileDescriptors.Item(oldFilePath).ReplaceReference(newFilePath)
Catch ex As Exception
errorRename.add(fileName)
End Try
' Exclui o arquivo antigo
Try
System.IO.File.Delete(oldFilePath)
Catch ex As Exception
errorRemove.add(fileName)
End Try
Next
Solved! Go to Solution.