Message 1 of 3

Not applicable
08-24-2020
09:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I got this code here in inventor forum. Modified the initial directory to go directly where the part was saved. It works fine in Inventor 2020 but not in 2017.
Sub Main() Dim oDoc As DrawingDocument = ThisDoc.Document oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View") If oView Is Nothing Then Exit Sub oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName) oModelLength = oModelDoc.Length 'oModelPN = iProperties.Value(oModelDoc, "Project", "Part Number") 'MessageBox.Show(x, "oModelDoc") oFullFilename = oView.ReferencedDocumentDescriptor.ReferencedDocument.fullfilename oInitDir = Left(oFullFilename, Len(oFullFilename) -oModelLength) 'MessageBox.Show(oFullFilename, "Title")'MessageBox.Show(oInitDir, "Title") Dim oFileDlg As Inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*" oFileDlg.DialogTitle = "Select a File" 'oFileDlg.InitialDirectory = ThisDoc.Path oFileDlg.InitialDirectory = oInitDir ' this is my additional code oFileDlg.CancelError = True On Error Resume Next oFileDlg.ShowOpen() If oFileDlg.FileName = "" Then Exit Sub NewFullFilename = oFileDlg.FileName Call ReplaceFileReference(oDoc, oFullFilename, NewFullFilename) iLogicVb.UpdateWhenDone = True End Sub Sub ReplaceFileReference(oDoc As Document, oRefToRemove As String, oRefToInclude As String) For Each oFD In oDoc.File.ReferencedFileDescriptors If oFD.FullFileName = oRefToRemove oFD.ReplaceReference(oRefToInclude) End If Next End Sub
Solved! Go to Solution.