几何尺寸与公差论坛------致力于产品几何量公差标准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)
-   DirectDWG (http://www.dimcax.com/hust/forumdisplay.php?f=89)
-   -   【转帖】looking for info on attributes (http://www.dimcax.com/hust/showthread.php?t=17125)

yang686526 2009-05-06 05:20 PM

【转帖】looking for info on attributes
 
looking for info on attributes
looking for info on attributes
what is the function of oddbattribute::setattributefromblock ?
in the version of the documentation i have the entry for it is blank (other than a parameter listing)
(i think i can guess from the name, but i'd rather have some confirmation if possible)
thanks
different question...
ok well testing revealed what i wanted to know there, but i'm still having issues with what lead me to this question...
how do i set the position of an attribute connected to a blockreference? setposition seems to have no effect at all on the text position.
coordinates of attribute definition entity inside block table record are stored in block space.
coordinates of attribute entity attached to block reference entity are stored in wordl space (block space + block reference entity transform).
oddbattribute::setattributefromblock(odgematrix3d& )
converts attribute's geometry by given matrix (usually obtained by oddbblockreference::blocktransform() call).
oddbattribute::setattributefromblock(oddbattribute definition *, odgematrix3d&)
uses given attribute definition as template to initialize attribute entity and after that converts it by given matrix.
if you want to place attribute entity into default position defined by attdef calling the last method would be enough - you need not set position.
sergey slezkin
quote:
originally posted by sergey slezkin
coordinates of attribute definition entity inside block table record are stored in block space.
coordinates of attribute entity attached to block reference entity are stored in wordl space (block space + block reference entity transform).
oddbattribute::setattributefromblock(odgematrix3d& )
converts attribute's geometry by given matrix (usually obtained by oddbblockreference::blocktransform() call).
oddbattribute::setattributefromblock(oddbattribute definition *, odgematrix3d&)
uses given attribute definition as template to initialize attribute entity and after that converts it by given matrix.
if you want to place attribute entity into default position defined by attdef calling the last method would be enough - you need not set position.
thanks for the clarification. the problem i'm having must be related to something else then. whether or not i try to set the position of the attribute on the block reference, all of the attributes i insert appear at (0,0). however, if i manually try to insert block references into the file (using autocad) the attributes appear correctly.
here's the code i use to create the blocks:
oddbobjectid createerrorblock(oddbdatabaseptr pdb, odstring blkname){
// open the block table -- prepair to move geometry
oddbblocktableptr pblocks = pdb->getblocktableid().safeopenobject(oddb::kforwrite) ;
//attempt to find the block before inserting
oddbobjectid blkid = pblocks->getat(blkname);
if(blkid.isnull()){
//create block here
oddbblocktablerecordptr pentry = oddbblocktablerecord::createobject();
// block must have a name before adding it to the table.
pentry->setname(blkname);
//create conventional error marker
//--create circle
oddbcircleptr errcircle = oddbcircle::createobject();
errcircle->setcenter(odgepoint3d(0,0,0));
errcircle->setradius(1.0);
//--set circle color
errcircle->setcolorindex(1);
//add to pentry
pentry->appendoddbentity(errcircle);
//create text attribute
oddbattributedefinitionptr def = oddbattributedefinition::createobject();
def->setprompt("enter error type");
def->settag("error");
def->settextstring("error");//default value
def->setinvisible(false);
def->setposition(odgepoint3d(-0.977478,-0.230034,0));
//def->setposition(odgepoint3d(-0.488739,0.230034,0));
def->setheight(0.5);
def->sethorizontalmode(oddb::ktextcenter);
def->setverticalmode(oddb::ktextvertmid);
def->setcolorindex(1);
oddbtextstyletablerecordptr txtstyle = oddbtextstyletablerecord::createobject();
txtstyle->settextsize(1.0);
def->settextstyle(txtstyle->objectid());
//add to pentry
pentry->appendoddbentity(def);
//add the object to the table.
cerr<<"adding block!"<<endl;
blkid = pblocks->add(pentry);
}
return blkid;
}
here's the code i use to create the block inserts:
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->settextstring(lbltext);
newblk->appendattribute(def);
}
}
}
//insert into modelspace
addentity(pdb, newblk);
return newblk->objectid();
}
thanks
found the problem
ok nevermind.
i needed to set the alignment point using setalignmentpoint, not the setposition method that i was using...
it depends on text alignment. if alignment is "left/base line" you need to use setposition(). if alignment is "fit" or "aligned" - both position and alignmentpoint.
in other cases - setalignmentpoint should be used.
sergey slezkin


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