Ilogic save as dialog box does not overwrite file

Ilogic save as dialog box does not overwrite file

Anonymous
Not applicable
1,519 Views
3 Replies
Message 1 of 4

Ilogic save as dialog box does not overwrite file

Anonymous
Not applicable

I am using the code below (from the blog From the trenches with Autodesk Inventor) to prompt the user to save the file. If they want to keep the same file name I get the dialog box "confirm save as" "Do you want to replace it" if I click "yes" it doesn't work.

 

Can you help?

Thanks

 

'define the active document
oDoc = ThisDoc.Document
'create a file dialog box
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)


'check file type and set dialog filter
If oDoc.DocumentType = kPartDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If


'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
'set the file name string to use in the input box
oFileDlg.FileName = ThisDoc.FileName(False) 'without extension


'work with an error created by the user backing out of the save 
oFileDlg.CancelError = True
On Error Resume Next
'specify the file dialog as a save dialog (rather than a open dialog)
oFileDlg.ShowSave()


'catch an empty string in the imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName
'save the file 
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If

 

0 Likes
1,520 Views
3 Replies
Replies (3)
Message 2 of 4

wayne.brill
Collaborator
Collaborator

Hello Mikey,

 

I get the error in the screenshot below when I use the Inventor drop down and run SaveAs and try to save over a file that is open in Inventor. I am not sure why the error does not occur when you use the dialog in iLogic. The error does occur if you run similar code in VBA that uses FileDialog.

 

SaveAs_Document_Name.jpg

 

 

You could just call Save() on the document to save the open document. If you want to do a SaveAs you could set the use an InputBox to get the  path and name.

 

If you want to report the behavior with iLogic not showing the error please post it on the Inventor idea station:

http://forums.autodesk.com/t5/inventor-ideastation/idb-p/v1232/tab/most-recent

 

 

Thanks,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 4

Owner2229
Advisor
Advisor

Hi, in order to save it under the same name you have to change the last part of your code a bit:

 

 

' Catch an empty string in the imput
If Err.Number <> 0 Then
    MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
    MyFile = oFileDlg.FileName
    ' Save the file
Dim CurrentName As String = ThisDoc.ThisDoc.PathAndFileName(True)
If MyFile = CurrentName Then

oDoc.Save
Else oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If End If

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 4 of 4

RoyWickrama_RWEI
Advisor
Advisor

Thanks for this part of the coding. I used it as shown below in my coding to get around the similar problem.

 

	If iProperties.Value("Project", "Part Number") <> "" Then
		oNewFFile = iProperties.Value("Project", "Part Number")
		oDoc.SaveAs(oFileDlg.FileName, False) 'True = Save As Copy & False = Save As
	Else
		Dim CurrentName As String = ThisDoc.PathAndFileName(True)
		oFileDlg.ShowSave()
		oNewFFile = oFileDlg.FileName
		oDoc.SaveAs(oNewFFile, False) 'True = Save As Copy & False = Save As
	End If

Roy Wickrama

 

0 Likes