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

    }
}
相关推荐
廋到被风吹走10 小时前
【Spring】事务管理深度解析|从原理到实战
java·spring
武藤一雄10 小时前
C#:进程/线程/多线程/AppDomain详解
后端·微软·c#·asp.net·.net·wpf·.netcore
思成不止于此10 小时前
【MySQL 零基础入门】DDL 核心语法全解析:数据库与表结构操作篇
数据库·笔记·学习·mysql
lkbhua莱克瓦2410 小时前
Java进阶——IO流
java·开发语言·笔记·学习方法·io流
韩立学长10 小时前
【开题答辩实录分享】以《自选便利店商品分类管理系统》为例进行选题答辩实录分享
java·mysql·web
aspirestro三水哥10 小时前
2.5构建Xenomai测试与演示镜像
数据库·rtos·xenomai
阿杰同学10 小时前
Java中55种锁,高级面试题,最新面试题
java·开发语言
随机昵称_12345610 小时前
postgresql连接报错Invalid SCRAM client initialization
数据库·postgresql
清晓粼溪10 小时前
SpringCloud01-基础概念
java·开发语言·spring cloud
路边草随风10 小时前
java实现发布flink yarn application模式作业
java·大数据·flink·yarn