输出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
            }
        }

    }
}
相关推荐
憧憬blog1 小时前
【Kiro开发集训营】拒绝“屎山”堆积:在 Kiro 中重构“需求-代码”的血缘关系
java·开发语言·kiro
青春:一叶知秋1 小时前
【Redis存储】List列表
数据库·redis·缓存
e***74952 小时前
Spring Security 官网文档学习
java·学习·spring
n***i952 小时前
Java NIO文件操作
java·开发语言·nio
笃行客从不躺平3 小时前
接口幂等性(Idempotency)
java
爆更小哇3 小时前
MyBatis的TypeHandler :优雅地实现数据加密与解密
数据库·后端·mybatis
Hero | 柒4 小时前
JAVA反射机制
java·spring·反射
j***63084 小时前
Springboot项目中线程池使用整理
java·spring boot·后端
likuolei4 小时前
Eclipse 创建 Java 接口
java·数据库·eclipse
q***54754 小时前
Spring Boot 经典九设计模式全览
java·spring boot·设计模式