Author Topic: How to save active drawing?  (Read 2368 times)

0 Members and 1 Guest are viewing this topic.

Viktor

  • Guest
How to save active drawing?
« on: October 06, 2009, 06:05:21 PM »
Whenver i try to save the active drawing's database I fail, how do you do it? must be something very simple i overlooked, but in the .net book i have saveas command is used like 3 times and they are not active drawings either way.

Something simple like this:
Code: [Select]
<CommandMethod("savetest", CommandFlags.UsePickSet)> _
    Public Sub savetest()
        Dim doc As Document = Application.DocumentManager.Open("C:\test\00F8NS01.dwg", False)
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        doc.SendStringToExecute("qsave" & vbCr, False, False, False) ' doesn't work, not sure why
        db.SaveAs(db.Filename, DwgVersion.Current) ' errors errors errors....
        doc.CloseAndDiscard()
    End Sub

Thanks.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: How to save active drawing?
« Reply #1 on: October 06, 2009, 06:28:03 PM »
does Filename have a value and have .dwg on the end?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to save active drawing?
« Reply #2 on: October 06, 2009, 06:33:10 PM »
You might need to set the CommandFlags to Session.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to save active drawing?
« Reply #3 on: October 06, 2009, 06:53:19 PM »
Have a look at the  'AutoCAD .NET Developer's Guide'

Search for
'Save and Close a Drawing' or 'SaveAs'

Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
 
[CommandMethod("SaveActiveDrawing")]
public static void SaveActiveDrawing()
{
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
  string strDWGName = acDoc.Name;
 
  object obj = Application.GetSystemVariable("DWGTITLED");
 
  // Check to see if the drawing has been named
  if (System.Convert.ToInt16(obj) == 0)
  {
      // If the drawing is using a default name (Drawing1, Drawing2, etc)
      // then provide a new name
      strDWGName = "c:\\MyDrawing.dwg";
  }
 
  // Save the active drawing
  acDoc.Database.SaveAs(strDWGName, true, DwgVersion.Current,
                        acDoc.Database.SecurityParameters);
}

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Viktor

  • Guest
Re: How to save active drawing?
« Reply #4 on: October 06, 2009, 09:13:59 PM »
Kerry you win the prize, after about 3 hours of pulling my hair I remember someone asked a similar question to Kean Wimsley on the experts exchange last week, started to dig around the web and found this as well:
acDoc.Database.SaveAs(acDoc.Name, True, DwgVersion.Current, acDoc.Database.SecurityParameters)

Sure enough this works, but it boggles my mind why leave the other 2 options still there if they don't work?

Thanks again to all.