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

用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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办