• 大小: 3.76MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-11-21
  • 语言: 其他
  • 标签: CAD  

资源简介

AutoCAD .NET开发指南-2012版与源码,可使用AutoCAD 2016 - 简体中文 (Simplified Chinese) 与vs2013进行学习,更改以下引用即可使用

资源截图

代码片段和文件信息

using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;




namespace chapter_01
{
    public class chp_01
    {

        //从模型空间检索实体对象
 
        [CommandMethod(“ListEntities“)]
        public static void ListEntities()
        {
          // 获取当前数据库,启动事务
          Document acDoc = Application.DocumentManager.MdiActiveDocument;
          Database acCurDb = acDoc.Database;
 
          using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
          {
              // 以读模式打开块表
              BlockTable acBlkTbl;
              acBlkTbl = acTrans.Getobject(acCurDb.BlockTableId
                                           OpenMode.ForRead) as BlockTable;
 
              // 以读模式打开块表记录模型空间
              BlockTableRecord acBlkTblRec;
              acBlkTblRec = acTrans.Getobject(acBlkTbl[BlockTableRecord.ModelSpace]
                                              OpenMode.ForRead) as BlockTableRecord;
 
              int nCnt = 0;
              acDoc.Editor.WriteMessage(“\nModel space objects: “);
 
              // 遍历模型空间里的每个对象,并
              // 显示找到的对象的类型
              foreach (objectId acObjId in acBlkTblRec)
              {
                  acDoc.Editor.WriteMessage(“\n“ + acObjId.objectClass.DxfName);
 
                  nCnt = nCnt + 1;
              }
 
              // 如果没发现对象则显示提示信息
              if (nCnt == 0)
              {
                  acDoc.Editor.WriteMessage(“\n No objects found“);
              }
 
              // 关闭事务
          }
        }


        //新建一个图层并将其添加到图层表

        [CommandMethod(“AddMylayer“)]
        public static void AddMylayer()
        {
            // 获取当前文档和数据库,并启动事务;
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 返回当前数据库的图层表
                layerTable acLyrTbl;
                acLyrTbl = acTrans.Getobject(acCurDb.layerTableId
                                             OpenMode.ForRead) as layerTable;

                // 检查图层表里是否有图层Mylayer
                if (acLyrTbl.Has(“Mylayer“) != true)
                {
                    // 以写模式打开图层表
                    acLyrTbl.UpgradeOpen();

                    // 新创建一个图层表记录,并命名为”Mylayer”
                    layerTableRecord acLyrTblRec = new layerTableRecord();
                    acLyrTblRec.Name = “Mylayer“;

                    // 添加新的图层表记录到图层表,添加事务
                    acLyrTbl.Add(acLyrTblRec);
                    acTrans.AddNewlyCreatedDBobject(acLyrTblRec true);

                    //提交修改
                    acTrans.Commit();
                }

                // 关闭事务,回收内存;
            }
        }


    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12288  2013-12-12 17:37  chapter_04\chapter_04\bin\Debug\chapter_04.dll

     文件      22016  2013-12-12 17:37  chapter_04\chapter_04\bin\Debug\chapter_04.pdb

     文件       3002  2019-04-11 16:34  chapter_04\chapter_04\chapter_04.csproj

     文件      25530  2013-12-12 17:37  chapter_04\chapter_04\Class1.cs

     文件        538  2013-12-12 17:37  chapter_04\chapter_04\obj\Debug\chapter_04.csproj.FileListAbsolute.txt

     文件      54420  2013-12-12 17:37  chapter_04\chapter_04\obj\Debug\chapter_04.csprojResolveAssemblyReference.cache

     文件      12288  2013-12-12 17:37  chapter_04\chapter_04\obj\Debug\chapter_04.dll

     文件      22016  2013-12-12 17:37  chapter_04\chapter_04\obj\Debug\chapter_04.pdb

     文件       6710  2019-04-11 16:34  chapter_04\chapter_04\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2019-04-11 16:34  chapter_04\chapter_04\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2019-04-11 16:34  chapter_04\chapter_04\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2019-04-11 16:34  chapter_04\chapter_04\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       1352  2013-12-10 20:02  chapter_04\chapter_04\Properties\AssemblyInfo.cs

     文件        920  2013-12-10 20:02  chapter_04\chapter_04.sln

    ..A..H.     15872  2013-12-12 17:37  chapter_04\chapter_04.suo

    ..A..H.     31232  2019-04-11 16:35  chapter_04\chapter_04.v12.suo

     文件        146  2014-01-06 10:22  chapter_05\chapter_05\bin\Debug\acad.err

     文件      16896  2014-01-06 17:39  chapter_05\chapter_05\bin\Debug\chapter_05.dll

     文件      26112  2014-01-06 17:39  chapter_05\chapter_05\bin\Debug\chapter_05.pdb

     文件       3002  2019-04-11 16:35  chapter_05\chapter_05\chapter_05.csproj

     文件      36563  2014-01-06 17:39  chapter_05\chapter_05\Class1.cs

     文件        950  2014-01-06 17:39  chapter_05\chapter_05\obj\Debug\chapter_05.csproj.FileListAbsolute.txt

     文件      16896  2014-01-06 17:39  chapter_05\chapter_05\obj\Debug\chapter_05.dll

     文件      26112  2014-01-06 17:39  chapter_05\chapter_05\obj\Debug\chapter_05.pdb

     文件       5853  2014-01-06 17:39  chapter_05\chapter_05\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1352  2013-12-14 14:59  chapter_05\chapter_05\Properties\AssemblyInfo.cs

     文件        920  2013-12-14 14:59  chapter_05\chapter_05.sln

    ..A..H.     16384  2014-01-06 17:39  chapter_05\chapter_05.suo

     文件       1633  2014-01-22 13:38  chapter_06\chapter_06\AcedSetCurrentVPort.txt

     文件      10752  2014-01-23 17:10  chapter_06\chapter_06\bin\Debug\chapter_06.dll

............此处省略420个文件信息

评论

共有 条评论