FileDialog: To Specify Save Location different from default

FileDialog: To Specify Save Location different from default

RoyWickrama_RWEI
Advisor Advisor
1,004 Views
3 Replies
Message 1 of 4

FileDialog: To Specify Save Location different from default

RoyWickrama_RWEI
Advisor
Advisor

I am doing with save copy as with a rule.

The "Save As" folder resorts to "Projects" despite I assigned different folder path. I saw many help in the forum: they all give the same result. Could someone help me please.

To Post.png

 

Sub Main()
oExit = MessageBox.Show("EXIT?", "Title", MessageBoxButtons.YesNo)
If oExit = vbYes Then Exit Sub

saveFolderStp = "C:\Roy XX\1551\STP"
saveFolderIges = "C:\Roy XX\1551\IGES"

oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim FFN_wExt As String 
FFN_wExt = ThisDrawing.ModelDocument.FullFileName

'specify word splitting characters "space" and "dash"
Dim Separators() As Char = {"\"c, "."c} Sentence = FFN_wExt
Words = Sentence.Split(Separators)
Dim oWords As New ArrayList
i = 0
For Each wrd In Words
oWords.Add(wrd)
i += 1
Next
oCount = oWords.Count

LFN_woExt = oWords(oCount-2)
LFN_revNumber = iProperties.Value("Project", "Revision Number")
revNumber_Edit = InputBox("REV. NUMBER (EDIT)", "EDIT", LFN_revNumber)
LFN_revNumber = revNumber_Edit
LFN_wRev = LFN_woExt & "-" & LFN_revNumber

Dim optionsSave As New ArrayList
oStp = ".stp"
oIges = ".iges"
oExit = "EXIT"
optionsSave.Add(oStp)
optionsSave.Add(oIges)
optionsSave.Add(oExit)
selectionSave = InputListBox("Prompt", optionsSave, optionsSave(0), Title := "FILE EXPORT", ListName := "List")
If selectionSave = oExit Then Exit Sub
If selectionSave = oSTP Then strFolder = saveFolderStp
If selectionSave = oIgs Then strFolder = saveFolderIges

saveCopyAs(FFN_wExt, strFolder, LFN_wRev, selectionSave)
End Sub


Sub saveCopyAs(FFN_wExt, strFolder, strFile, selectionSave)
oFile =  ThisApplication.Documents.Open(FFN_wExt, False) 'False/True: open the file is invisibe/visible
    oDoc = ThisDoc.Document
    xx = selectionSave
    Dim oFileDlg As inventor.FileDialog = Nothing
    InventorVb.Application.CreateFileDialog(oFileDlg)
    If xx = ".stp" Then
    oFileDlg.Filter = "STEP Files (*.stp; *.ste; *.step)|*.stp"
'    Else If xx = ".ipt" Then'    oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"'    Else If xx = ".iam" Then'    oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"'    Else If xx = ".idw" Then'    oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
    Else If xx = ".iges" Then
    oFileDlg.Filter = "IGES Files (*.igs; *.ige; *.iges)|*.iges"
    End If
    
    oFileDlg.InitialDirectory = strFolder    'ThisDoc.WorkspacePath()
    oFileDlg.FileName = strFile        'iProperties.Value("Project", "Part Number")
    oFileDlg.CancelError = True
    On Error Resume Next
    oFileDlg.ShowSave()
    If Err.Number <> 0 Then
    MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
    ElseIf oFileDlg.FileName <> "" Then
    MyFile = strFolder.FileName        'oFileDlg.FileName
    oDoc.SaveAs(MyFile, True) 'True = Save As Copy & False = Save As
    End If
oFile.Close 
End Sub

 

Accepted solutions (2)
1,005 Views
3 Replies
Replies (3)
Message 2 of 4

marcin_otręba
Advisor
Advisor

    Call ThisApplication.CreateFileDialog(ofiledlg)
  path = new path to be placed here
    ' Set the initial directory that will be displayed in the dialog.
    ofiledlg.InitialDirectory = path

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@RoyWickrama_RWEI,

 

Hoping that solution provided in below forum link would help.

 

https://forums.autodesk.com/t5/inventor-customization/initialdirectory-does-not-function-with-showop...

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 4 of 4

RoyWickrama_RWEI
Advisor
Advisor
Accepted solution

Thanks. It helped to to get around.

My rule as shown below, works fine.

Sub Main()
oExit = MessageBox.Show("EXIT?", "Title", MessageBoxButtons.YesNo)
If oExit = vbYes Then Exit Sub

saveFolderStp = "C:\Roy XX\1551\STP\"
saveFolderIges = "C:\Roy XX\1551\IGES\"

oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim FFN_wExt As String 
FFN_wExt = ThisDrawing.ModelDocument.FullFileName

'specify word splitting characters "space" and "dash"
Dim Separators() As Char = {"\"c, "."c}
Sentence = FFN_wExt
Words = Sentence.Split(Separators)
Dim oWords As New ArrayList
i = 0
For Each wrd In Words
oWords.Add(wrd)
i += 1
Next
oCount = oWords.Count

LFN_woExt = oWords(oCount-2)
LFN_revNumber = iProperties.Value("Project", "Revision Number")
revNumber_Edit = InputBox("REV. NUMBER (EDIT)", "EDIT", LFN_revNumber)
LFN_revNumber = revNumber_Edit
LFN_wRev = LFN_woExt & "-" & LFN_revNumber

Dim optionsSave As New ArrayList
oStp = ".stp"
oIges = ".iges"
oExit = "EXIT"
optionsSave.Add(oStp)
optionsSave.Add(oIges)
optionsSave.Add(oExit)
selectionSave = InputListBox("Prompt", optionsSave, optionsSave(0), Title := "FILE EXPORT", ListName := "List")
If selectionSave = oExit Then Exit Sub
If selectionSave = oSTP Then strFolder = saveFolderStp
If selectionSave = oIgs Then strFolder = saveFolderIges

saveCopyAs(FFN_wExt, strFolder, LFN_wRev, selectionSave)
End Sub


Sub saveCopyAs(FFN_wExt, strFolder, strFile, selectionSave)
'oFile =  ThisApplication.Documents.Open(FFN_wExt, True) 'False/True: open the file is invisibe/visible
'MessageBox.Show("strFolder: " & strFolder, "Title")
'MessageBox.Show("strFile: " & strFile, "Title")

    oDoc = ThisDoc.Document
    xx = selectionSave
	Dim oFileDlg As inventor.FileDialog = Nothing
	Call ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.InitialDirectory = strFolder    'ThisDoc.WorkspacePath()
    If xx = ".stp" Then
    oFileDlg.Filter = "STEP Files (*.stp; *.ste; *.step)|*.stp"
'    Else If xx = ".ipt" Then'    oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"'    Else If xx = ".iam" Then'    oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"'    Else If xx = ".idw" Then'    oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
    Else If xx = ".iges" Then
    oFileDlg.Filter = "IGES Files (*.igs; *.ige; *.iges)|*.iges"
    End If
	
    oFileDlg.DialogTitle = "Save Native"
'    Call oFileDlg.ShowOpen
	
    oFileDlg.FileName = strFolder & strFile		'"C:\Temp\DefaultFileName"	'strFile        'iProperties.Value("Project", "Part Number")
    oFileDlg.CancelError = True
    On Error Resume Next
    oFileDlg.ShowSave()
    If Err.Number <> 0 Then
    MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
    ElseIf oFileDlg.FileName <> "" Then
    MyFile = strFolder.FileName        'oFileDlg.FileName
    oDoc.SaveAs(MyFile, True) 'True = Save As Copy & False = Save As
    End If
'oFile.Close 
End Sub
0 Likes