几何尺寸与公差论坛------致力于产品几何量公差标准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-06, 05:20 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】incorrect block with attributes yang686526 DirectDWG 0 2009-05-06 03:47 PM
【转帖】how to have access block attributes yang686526 DirectDWG 0 2009-05-06 02:51 PM
【转帖】attributes in dwf expor yang686526 DirectDWG 0 2009-05-04 04:24 PM
【转帖】attributes in a block a not shown at the correct position yang686526 DirectDWG 0 2009-05-04 04:23 PM


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


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