输出CAD图中第一个图元类型——c#实现

复制改图元到一个新dwg中,启动代码可实现

如下图设置:

cs 复制代码
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary4
{
    public class Class1
    {

        [CommandMethod("ListEntities")]
        public static void ListEntities()
        {
            // Get the current document and database, and start a transaction
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 以只读方式打开块表记录   Open the Block table record for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // 以只读方式打开模型空间的块表记录    Open the Block table record Model space for read
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForRead) as BlockTableRecord;

                int nCnt = 0;
                acDoc.Editor.WriteMessage("\nModel space objects: ");

                // Step through each object in Model space and
                // display the type of object found
                foreach (ObjectId acObjId in acBlkTblRec)
                {
                    acDoc.Editor.WriteMessage("\n" + acObjId.ObjectClass.DxfName);

                    nCnt = nCnt + 1;
                }

                // If no objects are found then display a message
                if (nCnt == 0)
                {
                    acDoc.Editor.WriteMessage("\n No objects found");
                }

                // Dispose of the transaction
            }
        }

    }
}
相关推荐
2301_79218588几秒前
基于软件工程的结构化设计实验
数据库·oracle·软件工程
C雨后彩虹4 分钟前
ConcurrentHashMap入门:高并发场景的 HashMap替代方案
java·数据结构·哈希算法·集合·hashmap
小宇的天下7 分钟前
Allegro AXL (SKILL Extension) 手册核心内容结构化总结
数据库·oracle
weixin_4250230012 分钟前
Spring boot 2.7.18使用knife4j
java·spring boot·后端
自己的九又四分之三站台15 分钟前
基于OpenCV扶正扫描文件
人工智能·opencv·计算机视觉·c#
产幻少年16 分钟前
面试题八股
java
wanghowie16 分钟前
01.08 Java基础篇|设计模式深度解析
java·开发语言·设计模式
FuckPatience22 分钟前
C# 获取属性自定义特性报错:System.NotSupportedException:“泛型类型无效。
c#
CodeAmaz24 分钟前
Redis与数据库双写一致性详解
数据库·redis·缓存·数据一致性