Hi J.Oye
I'm new to vba/Ilogic programming but I think that a slightly modded version of save-copy-and-replace-with-i-logic
is what you are looking for!?
I would guess that following code in an assembly would do the job
Sub Main()
Dim dialog As New System.Windows.Forms.FolderBrowserDialog()
If dialog.ShowDialog()= System.Windows.Forms.DialogResult.OK Then
NewPath = dialog.SelectedPath
MsgBox(NewPath)
End If
Dim Path As String = NewPath
Dim FileChange As Boolean = False
InvDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
Dim refDoc As Document
For Each refDoc in refDocs
'MessageBox.show(refDoc.DisplayName)
'input box to enter new file name
NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name", refDoc.DisplayName)
'NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name", iProperties.Value(refDoc.DisplayName, "Project", "Part Number"))
'if the new file name is blank then use the same name
If NewFileName = "" Then
NewFileName = refDoc.DisplayName
End If
'if the user also types in the extesion then remove the extension.
If NewFileName.EndsWith(".ipt") = True Then
NewFileName = NewFileName.substring(0,NewFileName.length-4)
'MessageBox.show(NewFileName)
End If
'if there is an change in the name then do the following.
If refDoc.DisplayName <> NewFileName & ".ipt" Then
'check to see the file already exist. if it does then replace.
If System.IO.File.Exists(Path & NewFileName & ".ipt") Then
Component.Replace(refDoc.DisplayName, Path & NewFileName & ".ipt", True)
Else
Dim oldName As String = refDoc.DisplayName
'if it does not exist then recreate the file
refDoc.saveas(Path & NewFileName & ".ipt",False)
Call UpdateDrawing(Path, oldName, NewFileName)
End If
FileChange = True
End If
Next
If FileChange = True Then
NewAssemblyName = InputBox("What is the new file name for the assembly?", "New Assembly File Name", iProperties.Value("Project", "Part Number"))
If NewAssemblyName <> "" Then
Dim oldName As String = ThisDoc.FileName(True) 'include extension
ThisDoc.Document.SaveAs(Path & NewAssemblyName & ".iam" , False)
Call UpdateDrawing(Path, oldName, NewAssemblyName)
End If
End If
iLogicVb.UpdateWhenDone = True
End Sub
Private Sub UpdateDrawing (ByVal Path As String, ByVal oldName As String, ByVal newName As String)
Dim oDestinationDoc As DrawingDocument
Dim strFileExtension As String = oldName.substring(oldName.Length-4,4)
oldName = oldName.substring(0,oldName.Length-4)
Dim sFileName As String = Path & oldName & ".idw"
Try
If System.IO.File.Exists(sFileName) Then
oDestinationDoc = ThisApplication.Documents.Open(sFileName)
oDestinationDoc.saveas(Path & newName & ".idw",False)
Dim oDocDescriptor As DocumentDescriptor
oDocDescriptor = oDestinationDoc.ReferencedDocumentDescriptors.Item(1)
Dim oFileDescriptor As FileDescriptor
oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor
oFileDescriptor.ReplaceReference(Path & newName & strFileExtension)
oDestinationDoc.Update()
oDestinationDoc.Close
End If
Catch
oDestinationDoc.Close
MessageBox.Show("error")
End Try
End Sub