几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(VB.NET/C#) (http://www.dimcax.com/hust/forumdisplay.php?f=176)
-   -   【转帖】【求助】插入一个带属性的块,并更改其属性值 (http://www.dimcax.com/hust/showthread.php?t=9241)

yang686526 2009-04-20 05:31 PM

【转帖】【求助】插入一个带属性的块,并更改其属性值
 
【求助】插入一个带属性的块,并更改其属性值
www.dimcax.com
【求助】插入一个带属性的块,并更改其属性值
步骤如下:
1. 插入块,得到块参照
2. 打开你插入的块的块表记录
3. 循环打开这个块表记录中的各个实体,判断是否为块属性定义(attributedefinition)
4. 判断属性定义的标记是否是你要修改的
5. 新建一个块属性索引(attributereference)
6. 设置属性索引的特性与块属性定义的特性相同(用setpropertiesfrom)
7. 修改属性值(teststring)
8. 先把块参照加入数据库,再吧属性索引加入块参照,最后提交事务
using (transaction m_tr = db.transactionmanager.starttransaction())
{
blocktablerecord m_btr = (blocktablerecord)m_tr.getobject(db.currentspaceid, openmode.forwrite);
blockreference m_blkref = new blockreference(m_insertpoint, m_blockid);//插入一个块参照
list<attributereference> m_atteflist = new list<attributereference>();//保存你要修改的个个属性定义
blocktablerecord m_refbtr=m_tr.getobject(m_blkref.blcoktablerecord,openmode.forwite);//打开原块的块表记录
foreach(objectid id in m_refbtr)
{
dbobject m_obj=m_tr.getobject(id,openmode.forread);
if(m_obj is attributedefinition)//判断是否是块属性定义
{
attributedefinition m_attdef=m_obj as attributedefinition;//得到块属性定义
//下面开始修改你的属性值
if(m_attdef.tag==你的属性标记)
{
attributereference m_attref = new attributereference();//新建一个块属性索引
m_attref.setpropertiesfrom(m_attdef);//设置块属性索引的特性(来源于块属性定义中的特性)
m_attref.tag=m_attdef.tag;//设置属性标记(我晕,为什么setpropertiesfrom没直接拷贝进来?)
m_attref.textstring=属性新值;//这才是你要修改的
//其他如position,height,style,rotation如果不修改,就直接赋予m_attdef的值

m_atteflist.add(m_attref);
}
//继续修改其他属性(用循环好点哈)
}
}
m_insertblockid = m_btr.appendentity(m_blkref );
foreach (attributereference attref in m_attreflist)
{
m_blkref .attributecollection.appendattribute(attref);属性索引加入块参照
m_tr.addnewlycreateddbobject(attref, true);
}
m_tr.addnewlycreateddbobject(m_bref, true);
m_tr.commit();
}
复制代码


所有的时间均为北京时间。 现在的时间是 06:11 AM.