iLogic initial directory in 2017 doesnt work

iLogic initial directory in 2017 doesnt work

Anonymous
Not applicable
517 Views
2 Replies
Message 1 of 3

iLogic initial directory in 2017 doesnt work

Anonymous
Not applicable

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
0 Likes
Accepted solutions (1)
518 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution
Message 3 of 3

Anonymous
Not applicable

Thank you @JhoelForshav .

0 Likes