高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】attribute issues
attribute issues
attribute issues
i'm having intermittent issues related to adding attributes to block references. it appears that adding attributes to a particular block causes corruption issues in some files.
(this appears to be the case, as when i comment out the line of code that appends the attribute to the block reference, no problems occur)
here's the code snippet i'm working with:
code:
/*function: inserterrmark
*purpose: inserts an error marker at the specified coordinates in the specified database.
*input: (oddbdatabaseptr) pdb - database to insert into.
* (odgepoint3d) insertpt - point to put the error at
* (odstring) lbltext - text to print on the marker
*output: (oddbobjectid) - id of the new error marker
*/
oddbobjectid inserterrmark(oddbdatabaseptr pdb, odgepoint3d insertpt, odstring lbltext){
//make sure error block exists
oddbobjectid errblock = createerrorblock(pdb, "general_error");
//open record to insert error mark
oddbblockreferenceptr newblk = oddbblockreference::createobject();
//set to block def
newblk->setblocktablerecord(errblock);
if(insertpt.x==0&&insertpt.y==0){
cerr<<"("<<insertpt.x<<", "<<insertpt.y<<")"<<endl;
}
//insert point
newblk->setposition(insertpt);
//add text attribute.... connect it back the the attributedef attached to the blockdef
oddbblocktablerecordptr blkent = errblock.safeopenobject(oddb::kforwrite);
if(blkent->hasattributedefinitions()){
oddbobjectiteratorptr attptr = blkent->newiterator();
for(; !attptr->done(); attptr->step()){
if(strcmp(attptr->entity()->isa()->name(),"acdbattributedefinition")==0){
oddbattributeptr def = oddbattribute::createobject();
odgematrix3d mat3d;
mat3d.settoidentity();
def->setattributefromblock(oddbattributedefinitionptr(attptr->entity()), mat3d);
def->setposition(insertpt);
def->setalignmentpoint(insertpt);
cout<<"insert point: ("<<insertpt.x<<", "<<insertpt.y<<")"<<endl;
cout<<def->textstring();
def->settextstring(lbltext);
cout<<"->"<<def->textstring()<<endl;
def->setinvisible(false);
newblk->appendattribute(def);
}
}
oddbobjectiteratorptr attiter = newblk->attributeiterator();
int numattrib = 0;
for (; !attiter->done(); attiter->step()){
numattrib++;
}
}
//insert into modelspace
if(addentity(pdb, newblk)==0){
cerr<<"adding to error"<<endl;
if(!haslayer(pdb,"error")){
oddbobjectid tmp = addlayer(pdb, "error");
}
newblk->setlayer("error");
cerr<<"added to error"<<endl;
//insert point
newblk->setposition(insertpt);
}
being that i am restricted from sharing these files, can you recommend an area for me to look into that might cause this type of issue?
hi,
your code seems to be correct.
what means "causes corruption issues" ?
try to generate such file with no confidential information (or remove all such information from existing bug file).
might have been corrupt
when i attempted to create a file without the confidential info, i could not reproduce the error, so i think the file might be corrupt. i'll let you know if i run into it again though.
if you have this problem not always but with some specific file(s) try to check them with autocad's recover command and in odamfcapp sample (file/recover)
they may report errors.
sergey slezkin
|