欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > 查询当前文档所有块表记录名称(blocktablerecord)及模型空间中实体对象—— cad c# 二次开发

查询当前文档所有块表记录名称(blocktablerecord)及模型空间中实体对象—— cad c# 二次开发

2025/9/20 21:17:04 来源:https://blog.csdn.net/yongshiqq/article/details/144580360  浏览:    关键词:查询当前文档所有块表记录名称(blocktablerecord)及模型空间中实体对象—— cad c# 二次开发

运行dll文件,查询结果输出到命令行。

效果如下:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;namespace AcTools
{public class Class1{[CommandMethod("xx")]public void XX(){Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor editor = doc.Editor;using (Transaction tr = db.TransactionManager.StartTransaction()){// Open the Block table for readBlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;int count = 0;foreach (ObjectId blkId in bt){count += 1;BlockTableRecord blkRec = tr.GetObject(blkId, OpenMode.ForRead) as BlockTableRecord;editor.WriteMessage($"\n第{count}个快表记录:...... {blkRec.Name}\n");// Optionally, iterate through the block contentsint entcount = 0;foreach (ObjectId objId in blkRec){entcount +=1;Entity entity = tr.GetObject(objId, OpenMode.ForRead) as Entity;if (entity != null){editor.WriteMessage($" 包含内容{entcount}: Entity Type: {entity.GetType().Name}, ID: {objId}\n");}}}tr.Commit();editor.WriteMessage($" \n作者山水qq443440204\n");}}}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词