明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3266|回复: 1

[求助]如何插入带属性的块参照?已解决!

[复制链接]
发表于 2009-9-28 15:59 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2009-9-28 21:28:36 编辑

/

                       operBlkRec = (BlockTableRecord)operTrans.GetObject(operBlk[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                        InsertBlkRef = new BlockReference(Point3d.Origin, InsertBlkID);
                        InsertBlkRef.SetDatabaseDefaults();
                      
                        operBlkRec.AppendEntity(InsertBlkRef);
                        operTrans.AddNewlyCreatedDBObject(InsertBlkRef, true);

我的块定义是一个圆加一个属性,结果发现圆插入了,但属性没有插入,在cad中打开插入的块参照的特性,发现根本就没有属性那一栏。

还有,调试过程中发现插入后InsertBlkRef的MSITStore:E:\study\CAD\arxref(.net).chm::/2/Autodesk.AutoCAD.DatabaseServices.BlockReference.AttributeCollection.html">AttributeCollection是null。

不知道应该怎么样插入带属性定义的块参照,并且赋给块参照的属性具体的tag?

//插入快参照后还需要插入属性
                        int i = 0;
                        BlockTableRecord blkdef = (BlockTableRecord)operTrans.GetObject(InsertBlkRef.BlockTableRecord, OpenMode.ForRead);
                        foreach (ObjectId id in blkdef)
                        {
                            DBObject ent = operTrans.GetObject(id, OpenMode.ForRead);
                            if (ent is AttributeDefinition)
                            {
                                AttributeDefinition attdef = (AttributeDefinition)ent;
                                AttributeReference attref = new AttributeReference();
                                attref.SetAttributeFromBlock(attdef, InsertBlkRef.BlockTransform);
                                attref.TextString = loopInfor;
                                i++;
                                InsertBlkRef.AttributeCollection.AppendAttribute(attref);
                                operTrans.AddNewlyCreatedDBObject(attref, true);
                            }
                        }


发表于 2009-9-28 16:25 | 显示全部楼层
我的DBTransaction类有类似的函数,转帖过来吧
  1.          public Dictionary<AttributeDefinition, AttributeReference> AppendAttribToBlock(BlockReference blkref, List<string> atts)
  2.          {
  3.              BlockTableRecord blkdef = (BlockTableRecord)m_Transaction.GetObject(blkref.BlockTableRecord, OpenMode.ForRead);
  4.              int i = 0;
  5.              if (blkdef.HasAttributeDefinitions)
  6.              {
  7.                  Dictionary<AttributeDefinition, AttributeReference> attribs = new Dictionary<AttributeDefinition, AttributeReference>();
  8.                  foreach (ObjectId id in blkdef)
  9.                  {
  10.                      DBObject ent = GetObject(id, OpenMode.ForRead);
  11.                      if (ent is AttributeDefinition)
  12.                      {
  13.                          AttributeDefinition attdef = (AttributeDefinition)ent;
  14.                          AttributeReference attref = new AttributeReference();
  15.                          attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
  16.                          if (i < atts.Count)
  17.                              attref.TextString = atts[i];
  18.                          else
  19.                              attref.TextString = attdef.TextString;
  20.                          i++;
  21.                          blkref.AttributeCollection.AppendAttribute(attref);
  22.                          m_Transaction.AddNewlyCreatedDBObject(attref, true);
  23.                          attribs.Add(attdef, attref);
  24.                      }
  25.                  }
  26.                  return attribs;
  27.              }
  28.              return null;
  29.          }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-18 13:46 , Processed in 0.149209 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表