高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】setting Imported External Block Attribute Text Values
setting imported external block attribute text values
setting imported external block attribute text values
hi,
i am importing an external block with text attributes. i am trying to set the attribute text value using the following code but no attribute value is displayed in the saved dwg file where the block is inserted(the block is displayed correctly; the value is set correctly but not displayed).
char sattributetag[100];
char sattributevalue[100];
sprintf(sattributetag,"%s","ref");
sprintf(sattributevalue,"%s","test_text_123_123");
oddbblocktablerecordptr blkent = oriblockid.safeopenobject(oddb::kforwrite);
if(blkent->hasattributedefinitions())
{
oddbobjectiteratorptr attptr = blkent->newiterator();
for(; !attptr->done(); attptr->step())
{
if(strcmp(attptr->entity()->isa()->name(),"acdbattributedefinition")==0)
{
oddbattributedefinitionptr def = attptr->entity();
char scurrenttag[100];
sprintf(scurrenttag,"%s",def->tag());
if(stricmp(sattributetag,scurrenttag) == 0)
{
def->upgradeopen();
if(def->iswriteenabled())
{
def->settextstring(sattributevalue);
def->setdatabasedefaults();
}
break;
}
}
}
}
is settextstring() all that is required to update the text value and display it in the new drawing?
any ideas?
regards,
marc
last edited by marc; 27th october 2005 at 04:11 amfff">.
hi ,
i added the following to the code and the set attribute is displaying ok.
def->setconstant(true);
so the issue is resolved. final code is:
char sattributetag[100];
char sattributevalue[100];
sprintf(sattributetag,"%s","ref");
sprintf(sattributevalue,"%s","test_text_123_123");
oddbblocktablerecordptr blkent = oriblockid.safeopenobject(oddb::kforwrite);
if(blkent->hasattributedefinitions())
{
oddbobjectiteratorptr attptr = blkent->newiterator();
for(; !attptr->done(); attptr->step())
{
if(strcmp(attptr->entity()->isa()->name(),"acdbattributedefinition")==0)
{
oddbattributedefinitionptr def = attptr->entity();
char scurrenttag[100];
sprintf(scurrenttag,"%s",def->tag());
if(stricmp(sattributetag,scurrenttag) == 0)
{
def->upgradeopen();
if(def->iswriteenabled())
{
def->settextstring(sattributevalue);
def->setdatabasedefaults();
def->setconstant(true);
}
break;
}
}
}
}
attribute definitions can be inside a block (block definition).
attributes are attached to block reference.
attribute definitions simply define which attributes should be attached to block reference.
attribute definitions are displayed only if they are inside a layout block (model or paper space). if attribute definition is inside "normal" block it is not displayed - corresponding attributes attached to block reference are displayed.
the only exception is if attribute definition is constant.
sergey slezkin
thanks. i will look into implementing it by modifying the attribute definitions for the block reference and leaving the original block unchanged.
|