yangxuejingwu 2018-09-11 14:28 采纳率: 0%
浏览 2135

用C#程序,在AutoCAD中用entity.explode()怎么没能分解块呢?代码如下,望解答。

using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
TypedValue[] acTypValAr5 = new TypedValue[1];
acTypValAr5.SetValue(new TypedValue((int)DxfCode.BlockName, "1"), 0);
SelectionFilter acSelFtr5 = new SelectionFilter(acTypValAr5);
PromptSelectionResult acSSPrompt5 = acEd.SelectAll(acSelFtr5);
if (acSSPrompt5.Status == PromptStatus.OK)
{
//acDoc.SendStringToExecute("explode ", true, false, true);
SelectionSet acSSet5 = acSSPrompt5.Value;
DBObjectCollection objs = new DBObjectCollection();
foreach (ObjectId acSSetObject5 in acSSet5.GetObjectIds())
{
//Entity ent5 = acTrans.GetObject(acSSetObject5.ObjectId, OpenMode.ForWrite) as Entity;
Entity ent5 = acSSetObject5.GetObject(OpenMode.ForWrite) as Entity;
if (ent5 is BlockReference)
{
BlockReference blkRef = (BlockReference)acTrans.GetObject(acSSetObject5, OpenMode.ForWrite);
BlockTableRecord btr2 = (BlockTableRecord)acTrans.GetObject(blkRef.BlockTableRecord, OpenMode.ForWrite);
blkRef.Explode(objs);

                    }

                }
            }

            acTrans.Commit();
        }
  • 写回答

2条回答 默认 最新

  • weixin_42904638 2018-11-26 03:25
    关注

    炸开块后,需要将实体重新添加到模型空间,否则ent.Explode(objs)就没有起作用;
    //
    Database db = HostApplicationServices.WorkingDatabase;
    using (Transaction trans = db.TransactionManager.StartTransaction())
    {
    Entity ent = trans.GetObject(objectId, OpenMode.ForWrite) as Entity;
    DBObjectCollection objs = new DBObjectCollection();
    ent.Explode(objs);
    foreach (DBObject obj in objs)
    {
    if (obj is Entity)
    {
    db.AddToModelSpace((Entity)obj);
    }
    }
    if (IsDelateBlock)
    {
    objectId.Erase();
    }
    trans.Commit();
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?