.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding Options to The File Save As Dialog Box

4 REPLIES 4
Reply
Message 1 of 5
mgorecki
1096 Views, 4 Replies

Adding Options to The File Save As Dialog Box

Hello, I have the following function that opens the File "Save As" dialog box.  It gets fed a drawing number and allows the users to browse to a folder where they want to save it.  The problem is when a file already exists with the same name.  A message box pops up letting the user know that the file already exists and do they want to overwrite it.  The can pick yes to overwrite, but it doesn't really overwrite the old file, it seems like it opens it and then crashes when the rest of the program tries to run.

What I want to do is create a loop to determine if the file already exists.  If it does not exist, then save the path and drawing name as usual. 

If the drawing exists, I want to pop up a dialog giving two options; Overwrite, or Rename the current drawing.  If they pick Overwrite, I can have the program delete the old existing drawing and then just save this one.  If they pick Rename it will loop back to the "Save As" dialog giving the user the ability to change their drawing name (like add a "-1" to it.

Any help will be greatly appreciated.

 

Best regards,

Mark

 

 Public Function GetFilePathAndName(ByVal dwgNumber)
        podDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
        podDB = podDWG.Database
        podEd = podDWG.Editor
        podPSO.InitialDirectory = "W:\Work_in_Process"
        podPSO.InitialFileName = dwgNumber
        podPSO.Filter = "AutoCAD DWG Files|*.dwg"
        podPFR = podEd.GetFileNameForSave(podPSO)
        Select Case podPFR.Status
            Case EditorInput.PromptStatus.OK
                SaveDwgName = podPFR.StringResult
            Case EditorInput.PromptStatus.Cancel
                MsgBox("User Cancelled.")
        End Select
        Return SaveDwgName
    End Function

 

4 REPLIES 4
Message 2 of 5
mgorecki
in reply to: mgorecki

I guess what I want to know is, is there a way to turn off the automatic message that pops up saying "The drawing already exists, do you want to overwrite?"

I want to supply my own message.

Message 3 of 5
Artvegas
in reply to: mgorecki

The dialog shouldn't actually do anything with the file. It simply returns a file name string. The dialog shows the message you mentioned if a file with the same name already exists. This should only effect the returned PromptFileNameResult.Status property. It's probably a good idea to check the PromptFileNameResult.ReadOnly property before you try to save the file.

 

If there is a crash it will have something to do with your code and how it accesses the existing file (i.e. a file sharing issue where the file is already open and cannot be accessed for save). It could be open by anyone if you are on a network, so you need to program defensively for this.

 

Do you know about the Autodesk.AutoCAD.Windows.SaveFileDialog class? The ObjectARX docs mention a SaveFileDialogFlags.DoNotWarnIfFileExists enum which you pass into the SaveFileDialog constructor.

 

If you haven't used the SaveFileDialog class before then you can check out the following posts. There are some slight differences between the two that are discussed in detail.

 

Using AutoCAD's file selection dialog from .NET:
http://through-the-interface.typepad.com/through_the_interface/2007/08/using-autocads-.html

 

Allowing a user to select from multiple file formats inside AutoCAD using .NET:
http://through-the-interface.typepad.com/through_the_interface/2009/08/allowing-a-user-to-select-fro...

 

I'm sure this will do the trick for you. The only other alternative I can think of is to use a standard .NET SaveFileDialog class from either windows forms or wpf.

 

Art

Message 4 of 5
Artvegas
in reply to: Artvegas

One other thing... i don't know if it's possible to show your own message on top of the save dialog (i.e. while it is still open). Same goes for the standard .NET dialogs. I think you'd have to create your own save dialog which doesn't sound fun. But really you shouldn't need to go there if you are using the AutoCAD API dialogs correctly.
Message 5 of 5
mgorecki
in reply to: Artvegas

Hi Artvegas,

Thanks for the links.  I believe what was happening was that if the file existed already, and the user pick "Yes" to overwrite, the file was being opened.  Since the program creates blocks (and the blocks would already be created in the opened drawing) it would crash the program when AutoCad would ask if they wanted to re-define the block.

I've decided to go the simple route and just have the program delete the drawing name that the user enters before it saves the new drawing.  If the drawing already exists, then it's deleted, if not, then it does nothing.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost