若要创建新图形或打开现有图形,请使用对象的方法。该方法基于图形样板创建新的图形文件,并将该图形添加到 .该方法将打开现有图形文件。DocumentCollectionExtensionAddDocumentCollectionExtensionOpen 创建新图形本示例使用该方法基于 acad.dwt 图形样板文件创建新图形。Add VB.NETImports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime <CommandMethod("NewDrawing", CommandFlags.Session)> _ Public Sub NewDrawing() '' Specify the template to use, if the template is not found '' the default settings are used. Dim strTemplatePath As String = "acad.dwt" Dim acDocMgr As DocumentCollection = Application.DocumentManager Dim acDoc As Document = DocumentCollectionExtension.Add(acDocMgr, strTemplatePath) acDocMgr.MdiActiveDocument = acDoc End Sub C#using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; [CommandMethod("NewDrawing", CommandFlags.Session)] public static void NewDrawing() { // Specify the template to use, if the template is not found // the default settings are used. string strTemplatePath = "acad.dwt"; DocumentCollection acDocMgr = Application.DocumentManager; Document acDoc = acDocMgr.Add(strTemplatePath); acDocMgr.MdiActiveDocument = acDoc; } VBA/ActiveX 代码参考Sub NewDrawing() Dim strTemplatePath As String strTemplatePath = "acad.dwt" Dim docObj As AcadDocument Set docObj = ThisDrawing.Application.Documents.Add(strTemplatePath) End Sub 打开现有图形本示例使用该方法打开现有图形。在打开图形之前,代码会在尝试打开文件之前检查文件是否存在。Open VB.NETImports System.IO Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime <CommandMethod("OpenDrawing", CommandFlags.Session)> _ Public Sub OpenDrawing() Dim strFileName As String = "C:\campus.dwg" Dim acDocMgr As DocumentCollection = Application.DocumentManager If (File.Exists(strFileName)) Then DocumentCollectionExtension.Open(acDocMgr, strFileName, False) Else acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " & strFileName & _ " does not exist.") End If End Sub C#using System.IO; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; [CommandMethod("OpenDrawing", CommandFlags.Session)] public static void OpenDrawing() { string strFileName = "C:\\campus.dwg"; DocumentCollection acDocMgr = Application.DocumentManager; if (File.Exists(strFileName)) { acDocMgr.Open(strFileName, false); } else { acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName + " does not exist."); } } VBA/ActiveX 代码参考Sub OpenDrawing() Dim dwgName As String dwgName = "c:\campus.dwg" If Dir(dwgName) <> "" Then ThisDrawing.Application.Documents.Open dwgName Else MsgBox "File " & dwgName & " does not exist." End If End Sub 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:30
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.