AutoCAD NET获取没有属性的块的范围

问题描述

我正在尝试从图形中检索BlockReference的大小,该大小保存在其他位置,以便可以在自定义预览窗口中显示

我知道我可以使用BlockReference.GeometricExtents,但是这似乎包括属性的宽度以及实际的几何图形,并且很多块的属性都大于几何图形。

我还尝试访问块定义的宽度,因为该属性中不应包含任何内容,但是BlockTableRecord.Bounds似乎始终为空?

下面是一些示例代码

var doc = Autodesk.AutoCAD.applicationservices.Core.Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var selRes = ed.GetSelection();
if (selRes.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
    return;
var selSet = selRes.Value;

using var tr = doc.TransactionManager.StartTransaction();

var bt = (BlockTable)tr.Getobject(doc.Database.BlockTableId,OpenMode.ForRead);

foreach (var item in selSet.GetobjectIds())
{
    var obj = tr.Getobject(item,OpenMode.ForRead);
    if (!(obj is BlockReference blk))
        continue;
    ed.WriteMessage(Environment.NewLine + "Block: " + blk.Name);
    // Returns dimensions including attributes
    ed.WriteMessage(Environment.NewLine + $"Block Reference Dimensions: {blk.GeometricExtents.MaxPoint.X - blk.GeometricExtents.MinPoint.X} x {blk.GeometricExtents.MaxPoint.Y - blk.GeometricExtents.MinPoint.Y}"); 
    if (bt.Has(blk.Name))
    {
        var btr = (BlockTableRecord)tr.Getobject(bt[blk.Name],OpenMode.ForRead);
        if (btr.Bounds.HasValue)
            ed.WriteMessage(Environment.NewLine + $"Block DeFinition Dimensions: {btr.Bounds.Value.MaxPoint.X - btr.Bounds.Value.MinPoint.X} x {btr.Bounds.Value.MaxPoint.Y - btr.Bounds.Value.MinPoint.Y}");
        else
            // Always returns this
            ed.WriteMessage(Environment.NewLine + "No bounds found.");
    }
    else
        ed.WriteMessage(Environment.NewLine + $"No block deFinition found for '{blk.Name}'");
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)