使用对象的方法保存对象的内容。使用该方法时,可以通过提供参数来指定是否应重命名数据库以及是否应将磁盘上图形的备份重命名为备份文件。通过检查 DWGTITLED 系统变量的值,可以确定数据库是否使用默认名称 Drawing1、Drawing2 等。如果 DWGTITLED 为 0,则图形尚未重命名。SaveAsDatabaseDatabaseSaveAsTruebBakAndRename 有时,您需要检查活动图形是否有任何未保存的更改。在退出AutoCAD任务或开始新图形之前执行此操作是个好主意。要检查图形文件是否已更改,您需要检查 DBMOD 系统变量的值。 关闭图形对象的 or 方法用于关闭打开的图形并放弃或保存所做的任何更改。可以使用 关闭AutoCAD中所有打开的图形的方法。CloseAndDiscardCloseAndSaveDocumentCloseAllDocumentCollectionExtension 保存活动图形本示例将活动图形保存到“c:\MyDrawing.dwg”(如果当前未保存或使用其当前名称)。 VB.NETImports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Runtime <CommandMethod("SaveActiveDrawing")> _ Public Sub SaveActiveDrawing() Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim strDWGName As String = acDoc.Name Dim obj As Object = Application.GetSystemVariable("DWGTITLED") '' Check to see if the drawing has been named If System.Convert.ToInt16(obj) = 0 Then '' If the drawing is using a default name (Drawing1, Drawing2, etc) '' then provide a new name strDWGName = "c:\MyDrawing.dwg" End If '' Save the active drawing acDoc.Database.SaveAs(strDWGName, True, DwgVersion.Current, _ acDoc.Database.SecurityParameters) End Sub C#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); } VBA/ActiveX 代码参考Sub SaveActiveDrawing() ' Save the active drawing under a new name ThisDrawing.SaveAs "MyDrawing.dwg" End Sub 确定图形是否有未保存的更改本示例检查是否有未保存的更改,并与用户验证是否可以保存图形(如果不可以,请跳到末尾)。如果确定,请使用该方法保存当前图形,如下所示:SaveAs VB.NETImports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime <CommandMethod("DrawingSaved")> _ Public Sub DrawingSaved() Dim obj As Object = Application.GetSystemVariable("DBMOD") '' Check the value of DBMOD, if 0 then the drawing has not been changed If Not (System.Convert.ToInt16(obj) = 0) Then If MsgBox("Do you wish to save this drawing?", _ MsgBoxStyle.YesNo, _ "Save Drawing") = MsgBoxResult.Yes Then Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument acDoc.Database.SaveAs(acDoc.Name, True, DwgVersion.Current, _ acDoc.Database.SecurityParameters) End If End If End Sub C#using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; [CommandMethod("DrawingSaved")] public static void DrawingSaved() { object obj = Application.GetSystemVariable("DBMOD"); // Check the value of DBMOD, if 0 then the drawing has no unsaved changes if (System.Convert.ToInt16(obj) != 0) { if (System.Windows.Forms.MessageBox.Show("Do you wish to save this drawing?", "Save Drawing", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { Document acDoc = Application.DocumentManager.MdiActiveDocument; acDoc.Database.SaveAs(acDoc.Name, true, DwgVersion.Current, acDoc.Database.SecurityParameters); } } } VBA/ActiveX 代码参考Sub DrawingSaved() If Not (ThisDrawing.Saved) Then If MsgBox("Do you wish to save this drawing?", _ vbYesNo) = vbYes Then ThisDrawing.Save End If End If End Sub 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:23
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.