AutoCAD VBNET 当前文档保存
当前文档保存总出问题
现在借助com的方法实现了保存文件
<CommandMethod(NameOf(TT_SaveDrawing))>
Public Sub TT_SaveDrawing()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim aCadDoc = DocumentExtension.GetAcadDocument(doc) '获取当前文档的acadDocument com对象
Try
If Application.GetSystemVariable("DWGTITLED") = "0" Then
'https://help.autodesk.com/view/ACD/2023/CHS/?guid=GUID-1CA841EC-0313-4A34-8829-0CC0B5FB6FEE
Dim sfd As New Autodesk.AutoCAD.Windows.SaveFileDialog("输入文件名称", "", "dwg", "另存为", Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.NoFtpSites)
If sfd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
aCadDoc.SaveAs(sfd.Filename)
doc.Editor.WriteMessage("save as complete..." + Environment.NewLine)
Else
doc.Editor.WriteMessage("save as failure ..." + Environment.NewLine)
End If
Else
aCadDoc.Save() '调用com的save方法,执行文件保存
doc.Editor.WriteMessage("save complete..." + Environment.NewLine)
End If
'db.Save()==>前台打开图纸的时候(后台不会),使用保存函数db.Save(),无论如何都会出错., // 后台开图,用数据库保存;db.SaveAs(db.Filename, db.SecurityParameters);
Catch ex As System.Exception
Application.ShowAlertDialog(ex.StackTrace)
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(aCadDoc) '清理com对象
End Try
'Application.UpdateScreen()
End Sub