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

    }
}
相关推荐
GreatSQL3 小时前
MySQL迁移至GreatSQL后,timestamp字段插入报错解析
数据库
华仔啊3 小时前
主线程存了用户信息,子线程居然拿不到?ThreadLocal 背锅
java·后端
间彧3 小时前
Spring Boot项目中,Redis 如何同时执行多条命令
java·redis
召摇4 小时前
如何避免写垃圾代码:Java篇
java·后端·代码规范
vker4 小时前
第 1 天:单例模式(Singleton Pattern)—— 创建型模式
java·设计模式
expect7g4 小时前
COW、MOR、MOW
大数据·数据库·后端
我不是混子4 小时前
什么是内存泄漏?
java
程序员小假4 小时前
我们来说说当一个线程两次调用 start() 方法会出现什么情况?
java·后端
SimonKing5 小时前
Archery:开源、一站式的数据库 SQL 审核与运维平台
java·后端·程序员
DemonAvenger5 小时前
MySQL海量数据快速导入导出技巧:从实战到优化
数据库·mysql·性能优化