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

    }
}
相关推荐
pengdott5 小时前
Oracle RAC内存融合技术深度解析:集群性能的幕后引擎
数据库·oracle
csudata6 小时前
绿色便携版PostgreSQL发行版重磅发布
数据库·postgresql
阳光九叶草LXGZXJ6 小时前
达梦数据库-学习-48-DmDrs控制台命令(同步之Manager、CPT模块)
linux·运维·数据库·sql·学习
Hx_Ma166 小时前
SpringMVC框架提供的转发和重定向
java·开发语言·servlet
我科绝伦(Huanhuan Zhou)7 小时前
脚本再升级,兼容Oracle 26ai一键安装
数据库·oracle
期待のcode7 小时前
原子操作类LongAdder
java·开发语言
野生绿箭侠7 小时前
Ncos 2.3.2 版本集成达梦数据库
数据库
舟舟亢亢8 小时前
Java集合笔记总结
java·笔记
仍然.8 小时前
MYSQL--约束
数据库·mysql
A_nanda8 小时前
c# MOdbus rto读写串口,如何不相互影响
算法·c#·多线程