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

QSAVE Not Last

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Ron_M
1185 Views, 12 Replies

QSAVE Not Last

What is happening:  This is part of an InsertBorder routine that goes from a template (already opened) to a border in model space with all parameters set.  Everything works except the order that it works in.  In order for the routine to finish completely I need to get the saved path of the drawing which is not the original path to use to check for an existing file in that same path.  Unfortunately QSAVE won't fire in the middle like I need.  acDoc.Saveas won't work either because is just saves back to the original location without giving the operator a chance to enter in a new path, preferably through a explorer type dialog box.

 

In the below code I have my Insert_Click and what needs to happen in what order.  I need to somehow force QSAVE to trigger in the middle of other operations.  Currently QSAVE always fires last no matter where I put it.  I've tried looping the calls so that the code I need to run is outside the loop.  I've tried separate modules with calls to them separately.  I've tried everything that I can think of to get QSAVE to fire in the middle of the code as I need it to do.  I need the sub XRef to run after the QSAVE.  Any ideas?

 

 

    Private Sub Insert_Click(sender As Object, e As EventArgs) Handles Insert.Click
        'Close dialog
        Me.Close()
        SetParameters()
        AddLayer()
        AddBorder(PS1, PA1, SS1, DSC, BF, XR, FP)
        SaveDrawing()

        XRef(FP, XR)
    End Sub

 

12 REPLIES 12
Message 2 of 13
mcicognani
in reply to: Ron_M

Why don't you use the standard Autodesk.AutoCAD.Windows.SaveDialog dialog to ask for a new path and SaveAs() afterward?

 

Maybe you should shift your vision of VB.NET. It's not a script, it's a whole programming language and you have plenty of options, but maybe you need a few lines of code more.

 

And, for the QSAVE execution, the command will be executed at the end maybe because your command is executed in document space and not in session mode. This way the document command processor cannot execute more commands until yours ends.

Message 3 of 13
Ron_M
in reply to: mcicognani

Appreciate the reply.  Currently this has about 600 lines of code, a few more won't hurt (If I'm able to write them correctly).  As I am still new to .net I'm overcoming a knowledge defecit.

 

Autodesk.AutoCad.Windows.SaveDialog might do the trick.  I will be trying this shortly and will report back my results.

Message 4 of 13
Ron_M
in reply to: mcicognani

Thanks for starting me on the correct path.  Below works to a point.

        Dim SFD As New SaveFileDialog("", "", "dwg", "", Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension)
        If SFD.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            acDoc.Database.SaveAs(SFD.Filename, DwgVersion.Current)
        End If

 I can now save the drawing.  The issue I'm up against now is that after saving the drawing the open drawing (just saved) is not the one that was saved.  Does it have anything to do with the error I get that SaveFileDialog is not a member of Autodesk.Autocad.Windows?

Message 5 of 13
mcicognani
in reply to: Ron_M

No, I'd say the error you mention should be a compilation error, isn't it?

 

For the current file, now you have different options, you may just CloseAndDiscard() the current drawing, or alternatively use the CloseAndSave(String szFileName) function instead of the SaveAs(). If you tell us what is the big picture, I may provide some code samples (C# only, sorry).

 

Just remember that to be able to open and close documents and change the current document, your command must be run in Session mode (see CommandFlag.Session flag in the command method declaration.

Also, if you run in session mode, before alter a document, you need to lock it (see Document.LockDocument()).

 

 

Message 6 of 13
Ron_M
in reply to: mcicognani

Step by step:  Start with template file open, insert the border block, set the drawing parameters (dimstyle, dimscale, textstyle, etc.), save the file to a user specified location with a user specified name, check the location the drawing is saved to for the existence of a file that will be xref'd into the saved drawing, if that file doesn't exist go get it and copy to location, attach the xref to the saved file.

 

In order to check the location of the drawing it needs to be saved and I need to be able to pass back the location.  Right now with your help I can save the file specifying the name & location but after the save is complete the active file is the original unsaved file.

 

Message 7 of 13
mcicognani
in reply to: Ron_M

From my point of view, after the SaveFileDialog() call you have the full path (the dialog ask just for a saving location, it doesn't actually save anything), then you can do all of the check of this second file and attach it to the current, still active.

The last thing to do is save the complete file to the final location, that you may do with Database SaveAs().

 

Next I guess you want the file to assume this final location as default, I don't remember if the Document.Name or Database.FullpathName are read-only or you can set them... if they are writable you can just change the current drawing name.

 

I had a similar procedure, but I choosed a different approach: I used a standard OpenDialog() to choose the template, asked for the saving location with a SaveDialog() and instead of opening the template from the original location, I used to copy it to the final location using the System.IO functions, and then open it from there. This way I did not risk the original template to be saved by mistake and ruined. 

 

 

 

Message 8 of 13
Ron_M
in reply to: mcicognani

I'll check on the Name & Path.

 

I like your idea of pulling from the template as copy in the save location.  I'm going to add something like that in to further automate our operation.  Click icon (or enter command), open the template file, etc., etc.  That would allow me to control which template they're pulling from.

 

Currently we don't have a problem with template files being changed as they're all server based and the server is locked as read-only to all but myself & IT.  I have in the past mistakenly changed a file but I archive so often and we're live back-up so replacing is easy.

Message 9 of 13
Ron_M
in reply to: Ron_M

Still haven't gotten this to work.  It runs as expected, returns file name & path as expected, everything except leave me in the just saved drawing.  If I start in Drawing1 that is what I end in.  I need to end in the drawing saved & named.  Where am I going wrong?

 

    Public Sub SaveDrawing1()
        'Save drawing
        Dim SFD As New SaveFileDialog("", "", "dwg", "", Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension)
        If SFD.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            acDoc.SendStringToExecute("._zoom e ", False, False, False)
            strName = Path.GetFileNameWithoutExtension(SFD.Filename)
            strPath = Path.GetDirectoryName(SFD.Filename)
            FullPath = strPath + "\\" + strName + ".dwg"
            acDoc.Database.SaveAs(SFD.Filename, DwgVersion.Current)
            FP = System.IO.Path.GetFileName(SFD.Filename)
        End If
    End Sub

 

Message 10 of 13
mcicognani
in reply to: Ron_M

The SaveAs save a copy of the current drawing, but leave the previous value of Database.Filename and Document.Name unaltered.
Unfortunately, these properties are Read-only, so you cannot change them on the fly.
You may want to use DocumentExtension.CloseAndSave() and next reopen the document. Otherwise, there is always the copy of the template to the final destination folder before doing anything else...
I've no knowledge of any method able to rename the current document.
Message 11 of 13
moogalm
in reply to: Ron_M

Hi Ron,

Can you please try giving  a default directory to you save dialog , I'm not sure what bothering the code.

This idea is just top of my head.

Autodesk.AutoCAD.Windows.SaveFileDialog save = new Autodesk.AutoCAD.Windows.SaveFileDialog( "My Save Title", "c:\\folder\\", "dwg", string.Empty, Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.DefaultIsFolder); save.ShowDialog();

If this doesn't solve  do let me know, I will analyze.

Message 12 of 13
Ron_M
in reply to: mcicognani

As it turns out the reason I wasn't getting the saved drawing was that the form being modal and wasn't closing on the click ok event & me.close.  With the form still open I was unable to do anything to the open drawing as long as the form was open.  Changing the form to modeless fixes that.

Message 13 of 13
moogalm
in reply to: Ron_M

Hey there, Glad you found the fix , can you please mark your post as 'go to solution' , it may help others 🙂

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