‘ModelSpace’ 不是 ‘Autodesk.AutoCAD.ApplicationServices.Document’ 的成员。这是因为 ‘ModelSpace’ 是在 AutoCAD 中的 ‘BlockTableRecord’ 类中定义的成员,而不是在 ‘Document’ 类中定义的。如果您想访问 ‘ModelSpace’,可以使用 ‘Document’ 的 ‘BlockTable’ 属性来获取 ‘ModelSpace’ 的引用,然后使用 ‘ObjectId’ 来访问它。以下是一个示例代码:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
    BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
    BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
    
    // 访问ModelSpace中的实体
    foreach (ObjectId entityId in modelSpace)
    {
        Entity entity = tr.GetObject(entityId, OpenMode.ForRead) as Entity;
        // 处理实体
    }
    
    tr.Commit();
}
AutoCAD 中访问 ModelSpace 的方法

原文地址: https://www.cveoy.top/t/topic/qDIy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录