欢迎加我的QQ群:193522571,一起来讨论、交流!

eNotInDatabase,btr.AppendEntity(attNew);必须在AddNewlyCreatedDBObject前面

 

    public static void AddAttsToBlock(this ObjectId blockId, List<AttributeDefinition> atts, bool copyEntity = false)
    {
      Entity attNew;
      Database db = blockId.Database;//获取数据库对象
                                     //打开块表记录为写的状态
      BlockTableRecord btr = (BlockTableRecord)blockId.GetObject(OpenMode.ForWrite);
      //遍历属性定义对象列表
      foreach (AttributeDefinition att in atts)
      {
        attNew = att;
        if (copyEntity)
        {
          attNew = (Entity)att.Clone();
        }
        //此句必须在AddNewlyCreatedDBObject前面
        btr.AppendEntity(attNew);//为块表记录添加属性
        db.TransactionManager.AddNewlyCreatedDBObject(attNew, true);//通知事务处理
      }
      btr.DowngradeOpen();//为了安全,将块表记录的状态改为读
    }

 

posted @ 2023-04-24 16:01  swtool  阅读(62)  评论(0编辑  收藏  举报
欢迎加我的QQ群:193522571,一起来讨论、交流!