.NET

Reply
Valued Contributor
Ron_M
Posts: 64
Registered: ‎12-09-2013
Message 1 of 13 (171 Views)
Accepted Solution

QSAVE Not Last

171 Views, 12 Replies
07-08-2014 09:41 AM

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

 

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.

Distinguished Contributor
mcicognani
Posts: 125
Registered: ‎12-01-2004
Message 2 of 13 (144 Views)

Re: QSAVE Not Last

07-08-2014 11:22 PM 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.

Valued Contributor
Ron_M
Posts: 64
Registered: ‎12-09-2013
Message 3 of 13 (133 Views)

Re: QSAVE Not Last

07-09-2014 03:14 AM 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.

Valued Contributor
Ron_M
Posts: 64
Registered: ‎12-09-2013
Message 4 of 13 (122 Views)

Re: QSAVE Not Last

07-09-2014 04:42 AM 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?

Distinguished Contributor
mcicognani
Posts: 125
Registered: ‎12-01-2004
Message 5 of 13 (118 Views)

Re: QSAVE Not Last

07-09-2014 05:03 AM 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()).

 

 

Valued Contributor
Ron_M
Posts: 64
Registered: ‎12-09-2013
Message 6 of 13 (112 Views)

Re: QSAVE Not Last

07-09-2014 05:48 AM 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.

 

Distinguished Contributor
mcicognani
Posts: 125
Registered: ‎12-01-2004
Message 7 of 13 (107 Views)

Re: QSAVE Not Last

07-09-2014 06:34 AM 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. 

 

 

 

Valued Contributor
Ron_M
Posts: 64
Registered: ‎12-09-2013
Message 8 of 13 (104 Views)

Re: QSAVE Not Last

07-09-2014 06:48 AM 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.

Valued Contributor
Ron_M
Posts: 64
Registered: ‎12-09-2013
Message 9 of 13 (74 Views)

Re: QSAVE Not Last

07-14-2014 03:39 AM 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

 

Distinguished Contributor
mcicognani
Posts: 125
Registered: ‎12-01-2004
Message 10 of 13 (63 Views)

Re: QSAVE Not Last

07-14-2014 04:45 AM 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.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.