Help regarding renaming assembly file and a part file in it and saving it at same location using iLogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I have put together a code which renames the assembly file, one specific part file (which is Litecode Acrylic.ipt) within that assembly and all the related/referenced drawing files I want to rename and overwrites and saves them in the same directory.
The code is working fine for everything, except that after the replacement and everything, when I reopen the newly renamed assembly file,it is still referencing and asking for that one part file that I renamed using iLogic. All the other references are maintained fine, so I guess I am not replacing the reference correctly? I am using this line of code to replace reference of my part file;
Call assOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(ThisDoc.Path & "\" & newFileName)
Here is the full code in case someone needs it for their projects.
oApp = ThisApplication oAD = oApp.ActiveDocument oACD = oAD.ComponentDefinition MasterPos = oACD.RepresentationsManager.PositionalRepresentations.Item("Master") MasterPos.Activate ThisDoc.Save()
'Getting filenames/part numbers from excel file PN_AssyM = GoExcel.CellValue("SHEET_LXJ LIGHTSHEET linked data 082618.xlsx", "Sheet1", "J24") PN_Litecode = GoExcel.CellValue("SHEET_LXJ LIGHTSHEET linked data 082618.xlsx", "Sheet1", "J23") PN_Lightstick = GoExcel.CellValue("SHEET_LXJ LIGHTSHEET linked data 082618.xlsx", "Sheet1", "J25") ' Rename and replace main assembly file assemblyFileName = ThisDoc.PathAndFileName & ".iam" newAssemblyFileName = ThisDoc.Path & "\" & PN_AssyM & ".iam" drawingFileName = assemblyFileName.Replace(".iam", ".idw") newDrawingFileName = ThisDoc.Path & "\" & PN_AssyM & ".idw" IO.File.Move(assemblyFileName, newAssemblyFileName) 'Updating assembly drawing drawingFile = ThisApplication.Documents.Open(drawingFileName) drawingFile.ReferencedDocumentDescriptors.Item(1).ReferencedFileDescriptor.ReplaceReference(newAssemblyFileName) drawingFile.Update() drawingFile.Close IO.File.Move(drawingFileName, newDrawingFileName) 'Updating Litestick drawing oldLsDrawingFileName = ThisDoc.Path & "\" & "Lightstick Drawing.idw" newLsDrawingFileName = ThisDoc.Path & "\" & PN_Lightstick & ".idw" lsDrawingFile = ThisApplication.Documents.Open(oldLsDrawingFileName) lsDrawingFile.ReferencedDocumentDescriptors.Item(1).ReferencedFileDescriptor.ReplaceReference(newAssemblyFileName) lsDrawingFile.Update() lsDrawingFile.Close IO.File.Move(oldLsDrawingFileName, newLsDrawingFileName) ''Renaming and updating Litecode acrylic part file Dim fileMgr As FileManager fileMgr = ThisApplication.FileManager For Each assOcc As ComponentOccurrence In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences If assOcc.Definition.Document.DisplayName = "Litecode acrylic.ipt" Then oldFileName = "Litecode acrylic.ipt" newFileName = PN_Litecode & ".ipt" partDrawingFileName = ThisDoc.Path & "\" & "Litecode acrylic.idw" newPartDrawingFileName = ThisDoc.Path & "\" & PN_Litecode & ".idw" Call fileMgr.CopyFile(oldFileName, newFileName) Call assOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(ThisDoc.Path & "\" & newFileName) Call fileMgr.DeleteFile(oldFileName) ''Updating drawing file for litecode acrylic partDrawing = ThisApplication.Documents.Open(partDrawingFileName) partDrawing.ReferencedDocumentDescriptors.Item(1).ReferencedFileDescriptor.ReplaceReference(ThisDoc.Path & "\" & newFileName) partDrawing.Update() partDrawing.Close IO.File.Move(partDrawingFileName, newPartDrawingFileName) End If Next