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


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-05-07, 03:36 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】set Block Attribute Values

set block attribute values ...
set block attribute values ...
attributes in autocad block:
i want to assign values to the attributes in a blockreference (insert).
please let me know the best way that i could follow using the dwgdirect library functions to get access to the blockreference object and modify its attribute values.
other details:
dwgdirect 1.10, 1/23/2004
autocad 2002
vc++ 6.0
windows 2000 pro
more info
since no one responded yet, i assume more info is required. it seems like this should be easy to do, yet for some reason i am not getting the expected results ...
query:
i am trying to assign new value to the attributes in a block insert (block reference). find below the part of code which i am using.
can someone tell me why this code is not updating the attribute values in the block.
thanx in advance!
----------------------------------------------------------
void updateblocks(oddbblocktablerecordptr pblockptr) {
// get an entity iterator
oddbobjectiteratorptr pentiter = pblockptr->newiterator();
// for each attribute in the block
for(; !pentiter->done(); pentiter->step())
{
// open the entity
oddbentityptr pent = pentiter->entity(oddb::kforwrite);
if (pent->iskindof(oddbattributedefinition::desc()))
{
oddbattributedefinitionptr pattdef = pent;
pattdef->settextstring("new value");
}
}
}
your code is attempting to modify attribute definitions inside the block not attributes of block reference.
to get attributes of block reference use oddbblocktablereference::attributesiterator().
sergey slezkin
block attributes
quote:
originally posted by sergey slezkin
your code is attempting to modify attribute definitions inside the block not attributes of block reference.
to get attributes of block reference use oddbblocktablereference::attributesiterator().
thanx for the reply.
i guess you are mentioning about oddbblockreference::attributeiterator().
i am unable to get the pointer to blockreference from the block table record.
find below the code which i am using for iterating through the block table.
--------------------------------------------------------
oddbblocktableptr pblocks = pdb->getblocktableid().safeopenobject(oddb::kforwrite) ;
// get an iterator for the block table
oddbblocktableiteratorptr pblkiter = pblocks->newiterator();
oddbblocktablerecordptr pblockptr;
// for each block in the block table
for (pblkiter->start(); ! pblkiter->done(); pblkiter->step())
{
pblockptr = pblkiter->getrecord(oddb::kforwrite);
if (!strcmpi("*model_space", pblockptr->getname()) || !strcmpi("*paper_space", pblockptr->getname())) continue;
if (false == pblockptr->hasattributedefinitions()) continue;
updateblocks(pblockptr);
}
--------------------------------------------------------------
block definition (oddbblocktablerecord) may contain attribute definitions (oddbattributedefinition). block insertion (oddbblockreference) may have attribute values attached (oddbattribute).
each block (oddbblocktablerecord) may be inserted multiple times with different attribute values (oddbattribute entities attached to oddbblockreference).
in the first post you wrote that you you want to alter attributes of block reference.
in the last post you attached code modifying attribute definition.
block reference entity can be found while iterating model, paper spaces (or other blocks).
another method is using oddbblocktablerecord::getblockreferenceids(). it will return array of oddbblockreference ids referencing the oddbblocktablerecord.
sergey slezkin
block attribute (insert)
quote:
originally posted by sergey slezkin
block definition (oddbblocktablerecord) may contain attribute definitions (oddbattributedefinition). block insertion (oddbblockreference) may have attribute values attached (oddbattribute).
each block (oddbblocktablerecord) may be inserted multiple times with different attribute values (oddbattribute entities attached to oddbblockreference).
in the first post you wrote that you you want to alter attributes of block reference.
in the last post you attached code modifying attribute definition.
block reference entity can be found while iterating model, paper spaces (or other blocks).
another method is using oddbblocktablerecord::getblockreferenceids(). it will return array of oddbblockreference ids referencing the oddbblocktablerecord.
thanx for the suggestion.
yes, i want to update the value of te attribute in the insert and not definition.
i am unable to get the pointer to blockreference. also i tried using oddbblocktablerecord::getblockreferenceids() but the array was empty.
can you please send me the sample code to get the referenceids from the blocktable record...
find below the code which i am using for getting the referenceids
--------------------------------
oddbblocktableptr pblocks = pdb->getblocktableid().safeopenobject(oddb::kforwrite) ;
oddbblocktableiteratorptr pblkiter = pblocks->newiterator();
oddbblocktablerecordptr pblockptr;
oddbobjectidarray objarray;
oddbobjectid blkid;
// for each block in the block table
for (pblkiter->start(); ! pblkiter->done(); pblkiter->step())
{
pblockptr = pblkiter->getrecordid().safeopenobject(oddb::kforwrite);
pblockptr->getblockreferenceids(objarray);
if (objarray.isempty() == true) return;
blkid = objarray.getat(0);
}
due to dd bug getreferenceids() reurns empty array for loaded pre-r15 files. it should work for r15+ files. calling oddbdatabase::audit() fixes the problem.
sergey slezkin
set block reference attribute values
quote:
originally posted by sergey slezkin
due to dd bug getreferenceids() reurns empty array for loaded pre-r15 files. it should work for r15+ files. calling oddbdatabase::audit() fixes the problem.
thanx again...
i am working with autocad 2002 drawing files.
i did try with oddbdatabase::audit() as given below
------------
oddbauditinfo pinfo;
pinfo.setfixerrors(true);
pdb->auditdatabase(&pinfo);
-----------
even with the above lines in the code the getblockreferenceid() is empty.
please let me know how i could solve this problem....
i am unable to find some sample code which does update of blockreference attrib values.
are you sure that the block record returning empty array from getreferenceids() is really inserted in the drawing? maybe where are no block references of this block?
sergey slezkin
set block reference attributes
quote:
originally posted by sergey slezkin
are you sure that the block record returning empty array from getreferenceids() is really inserted in the drawing? maybe where are no block references of this block?
thanx once again....
finally i am able to get the pointer to block reference and assign values to the attributes...
here is the code which i have used...
let me know if i can improve this code further and optimize....
-------------------------
oddbblocktablerecordptr pblkrec = pdb->getmodelspaceid().openobject(oddb::kforwrite);;
oddbobjectiteratorptr pblkreciter = pblkrec->newiterator();
for (pblkreciter->start(); !pblkreciter->done(); pblkreciter->step())
{
oddbentityptr pentity = pblkreciter->objectid().safeopenobject();
oddbblockreferenceptr pblkref;
if (pentity->iskindof(oddbblockreference::desc()))
pblkref = pentity->objectid().openobject(oddb::kforwrite);
else continue;
oddbobjectiteratorptr pattiter = pblkref->attributeiterator();
for(; !pattiter->done(); pattiter->step())
{
// open the entity
oddbentityptr pent = pattiter->objectid().openobject(oddb::kforread);
if (pent->iskindof(oddbattribute::desc()))
{
oddbattributeptr pattdef = pblkref->openattribute(pattiter->objectid(), oddb::kforwrite);
pattdef->settextstring("testvalue");
}
}
i modified a bit your code to make it more compact.
but in such case you iterate through the all model space entities (where may be thousands of them). you probably need to iterate through paper spaces as well. and maybe through other blocks too (the block you are interested in may be inserted not into model space but into another block which is inserted into model or paper space (nested).
if you from the very beginning know the name of block which insertions should be altered (attributes modified) the shortest way is to get block reference ids from block table record.
oddbblocktablerecord::getreferenceids() should work if the block is realy inserted.
could you post to forum or e-mail me (see my profile) the file for which getreferenceids() does not work?
code:
oddbblocktablerecordptr pblkrec = pdb->getmodelspaceid().openobject(); //no need in opening for write
oddbobjectiteratorptr pblkreciter = pblkrec->newiterator();
for (pblkreciter->start(); !pblkreciter->done(); pblkreciter->step())
{
oddbblocreferenceptr pblkref = oddbblockreference::cast(pblkreciter->entity());
if (pblkref.isnull())
{ // not a block reference
continue;
}
oddbobjectiteratorptr pattiter = pblkref->attributeiterator();
for(; !pattiter->done(); pattiter->step())
{ // open the entity
oddbattributeptr pattdef = pattiter->entity(oddb::kforwrite);
pattdef->settextstring("testvalue");
}
}
sergey slezkin
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】memory leak issue yang686526 DirectDWG 0 2009-05-06 05:37 PM
【转帖】grouping in svg based on block hierarchy yang686526 DirectDWG 0 2009-05-05 11:41 AM
【转帖】color problem with hatch while vectorization yang686526 DirectDWG 0 2009-05-04 05:55 PM
【转帖】attributes in a block a not shown at the correct position yang686526 DirectDWG 0 2009-05-04 04:23 PM
【转帖】a dimension error yang686526 DirectDWG 0 2009-05-04 03:05 PM


所有的时间均为北京时间。 现在的时间是 08:57 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多