几何尺寸与公差论坛------致力于产品几何量公差标准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-04, 04:23 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】attributes in a block a not shown at the correct position

attributes in a block a not shown at the correct position
problem positioning attributes which belong to a block
hello ,
i want to copy a block of an existing drawing containing attributes and insert it as a definition and as a blockreference in a new drawing. when doing so with the code below, positionning geomerical elements works fine. however, the attributes are always positioned around the origin.
what i want to do in detail:
1. insert a block containing lines and attributes from a dxf drawing (=drawinga) to another dxf drawing (drawingb) as a block definition.
2. create a block instance (block record) of this block at a new position in drawingb.
my problem:
1. i can insert the block definition in drawingb including the attribute definitions
2. i can create a block instance and insert it at a given position (posx, posy). but now the problem: when i insert the block, the attributes will always be printed around the origin (0,0), whereas the geometrical elements of the block will be printed at the correct position. see the attached .dxf file for an example (if you try to insert the a blockreference of the block "basic" using autocad, everything works fine).
the function for inserting a block definition in drawingb is:
int insertblockfromdrawingasblockdefinition(const char* srcfilename, const char* srcblockname){
//opens the source database
oddbdatabaseptr psrcdb = opendatabase(srcfilename);
//add the block with name srcblockname to the destination db.
//this creates the block to the db
oddbobjectid blockdefidindb = pdb->insert(srcblockname,srcblockname, psrcdb, true);
//release the source db
psrcdb.release();
psrcdb = 0;
//add it the id to the array and return the index
return pobjarr->append(blockdefidindb);
}
to create an instance of the block in drawingb i use the following function:
int insertblockreferenceinmodelspace(
int blockdefinitionid, // id of block to be inserted
double xposition, double yposition, double rotation, double scale) {
//get the model space "block"
oddbobjectid blocktableid = pdb->getblocktableid();
oddbsymboltableptr pblocktable = blocktableid.safeopenobject();
oddbblocktablerecordptr pmodelspaceblock = pblocktable->getat("*model_space", oddb::kforwrite);
// create the block instance which will be inserted)
oddbblockreferenceptr pblockref = oddbblockreference::createobject();
// add the entity to the parent block (=model space block).
oddbobjectid blockrefid = pmodelspaceblock->appendoddbentity(pblockref);
// get the block defintion from the blocktablerecord
pblockref->setblocktablerecord(pobjarr->at(blockdefinitionid));
//set the properties
pblockref->setscalefactors(odgescale3d(scale, scale, 1.0));
pblockref->setposition(odgepoint3d(xposition, yposition, 0));
pblockref->setrotation(rotation *(m_pi / 180.0));
//add the attributes
oddbblocktablerecordptr pblockdefinition = pobjarr->at(blockdefinitionid).safeopenobject();
addattributestoblockreference(pblockref, pblockdefinition);
//add it the id to the array and return the index
return pobjarr->append(blockrefid);
}
the following is only a helper function, which creates the attributes in the blockreference using the corresponding attribute definitions:
void addattributestoblockreference(oddbblockreferencept r pblockref, oddbblocktablerecordptr pblockdefinition){
oddbobjectiteratorptr piter = pblockdefinition->newiterator();
for(piter->start(); !piter->done(); piter->step())
{
oddbentityptr pentity = piter->entity();
oddbattributedefinitionptr pattributedef = oddbattributedefinition::cast(pentity);
//add all attributes of this block's definition
//to the block reference (= block instance
if(!pattributedef.isnull())
{
oddbattributeptr pattribute = oddbattribute::createobject();
//append the attribute the the block reference
pblockref->appendattribute(pattribute);
pattribute->setpropertiesfrom (pattributedef, true);
pattribute->settag(pattributedef->tag());
pattribute->settextstring(pattributedef->textstring());
pattribute->setalignmentpoint (pattributedef->alignmentpoint());
pattribute->setheight (pattributedef->height());
pattribute->sethorizontalmode (pattributedef->horizontalmode());
pattribute->setnormal (pattributedef->normal());
pattribute->setoblique (pattributedef->oblique());
pattribute->setposition (pattributedef->position());
pattribute->setrotation (pattributedef->rotation());
pattribute->settextstring (pattributedef->textstring());
pattribute->settextstyle (pattributedef->textstyle());
pattribute->setwidthfactor (pattributedef->widthfactor());
}
}
}
cheers and thanks for any help,
christoph
attached files
you set the position of the attribute to be the same as the position of the definition.
you may want to add the position of the insert to it.
vladimir
hi valdimir,
that's true. but even when i replace the code in addattributestoblockreference(..) fff">to the following, it does not work:
void addattributestoblockreference(oddbblockreferencept r pblockref, oddbblocktablerecordptr pblockdefinition){
oddbobjectiteratorptr piter = pblockdefinition->newiterator();
for(piter->start(); !piter->done(); piter->step())
{
oddbentityptr pentity = piter->entity();
oddbattributedefinitionptr pattributedef = oddbattributedefinition::cast(pentity);
//add all attributes of this block's definition
//to the block reference (= block instance
if(!pattributedef.isnull())
{
oddbattributeptr pattribute = oddbattribute::createobject();
//append the attribute the the block reference
pblockref->appendattribute(pattribute);
pattribute->setpropertiesfrom (pattributedef, true);
pattribute->settag(pattributedef->tag());
pattribute->settextstring(pattributedef->textstring());
pattribute->setalignmentpoint (pattributedef->alignmentpoint());
pattribute->setheight (pattributedef->height());
pattribute->sethorizontalmode (pattributedef->horizontalmode());
pattribute->setnormal (pattributedef->normal());
pattribute->setoblique (pattributedef->oblique());
pattribute->setposition (odgepoint3d(pattributedef->position().x+ pblockref->position().x, pattributedef->position().y + pblockref->position().y ,0));
pattribute->setrotation (pattributedef->rotation());
pattribute->settextstring (pattributedef->textstring());
pattribute->settextstyle (pattributedef->textstyle());
pattribute->setwidthfactor (pattributedef->widthfactor());
}
}
}
well, it is easier just to apply block transform to the attributes. did you look at writeex sample?
vladimir
hi valdimir,
i looked at dbfiller::addblockdef(..).
there is a function call:
patt->transformby (blkxfm);
i added this to my function and it works!
there is one more question which i have now: i do the positioning of the blockref using:
pblockref->setposition(odgepoint3d(xposition, yposition, 0));
should i use
pblockref->transformby(blkxfm);
instead? or does it make no difference?
cheers and thanks a lot,
christoph
i think, it makes no difference
vladimir
hi vladimir,
i was able to set a block to a new location and to rotate a block using:
pblockref->setposition(odgepoint3d(xposition, yposition, 0));
pblockref->setrotation(odatoradian(rotation));
to translate an attribute and to rotate it, i needed to do the following (mix between odgematrixfff"> and pattribute->setrotation()fff">):
odgematrix3d blkxfm;
blkxfm.settranslation(pblockref->position().asvector());
pattribute->setrotation(pblockref->rotation());
apply the translation to the attribute
pattribute->transformby (blkxfm);
doing everything with odgematrix3d did not work. especially to call pblockreference->transformby(blkxfm)fff"> does not seem to have any effect! could there be an error related to that in the library? (the code examples below don't seem to have any effect!)
//rotate and translate the block
odgematrix3d blkxfm;
blkxfm.translation(odgepoint3d(xposition, yposition, 0).asvector());
blkxfm.rotation(odatoradian(rotation), odgevector3d.kzaxis, odgepoint3d(0, 0, 0));
pblockref->transformby(blkxfm);
//rotate and translate the attribute
odgematrix3d blkxfm;
blkxfm.rotation(pblockref->rotation(), odgevector3d.kzaxis, odgepoint3d.korigin);
blkxfm.settranslation(pblockref->position().asvector());
pattribute->transformby (blkxfm);
thanks for any help,
christoph
odgematrix3d::translation
odgematrix3d::rotation
are static methods returning rotation and translation matrices
vladimir
in the meantime i also found it out.
sorry for having disturbed you again...
cheers and thanks,
christoph
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】alignment and position in oddbte yang686526 DirectDWG 0 2009-05-04 03:55 PM
【转帖】a dimension error yang686526 DirectDWG 0 2009-05-04 03:05 PM
【转帖】asme - where to star yang686526 American standards 0 2009-04-29 07:28 PM
【转帖】editing blocks per drawing shee yang686526 SolidWorks二次开发 0 2009-04-13 10:39 AM


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


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