几何尺寸与公差论坛------致力于产品几何量公差标准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, 06:38 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】crash when using kdrcmanglename

crash when using kdrcmanglename
crash when using kdrcmanglename
hi,
i have certain problems in using the wblockcloneobjects() with the flag kdrcmanglename. if it is called several times to paste objects in one drawing, there are some exception thrown and after that there is a crash error. very often i have also duplicated layer names. this seems to happen at version 1.14.02. the previous dwgdirect versions seemed to work ok - but may be that flag was not implemented there...
here is a sample code to illustrate this.
code:
{
oddbobjectid idmodelspace,idtempmodelspace;
odgepoint3d pt3d = odgepoint3d(0.0,0.0,0.0);
oddbdatabase* pdb = getdocument()->m_pdb;
{
if(!idtempmodelspace.isnull())
if(!idtempmodelspace.iserased())
idtempmodelspace.database()->release();
oddbblocktablerecordptr pmodelspace = pdb->getmodelspaceid().safeopenobject(oddb::kforwrite);

//create a new layer
oddblayertablerecordptr player = oddblayertablerecord::createobject();
player->setname("uniquelayer");
player->setcolorindex(4);
//add created layer to the layertable;
oddblayertableptr playertable = pdb->getlayertableid().safeopenobject(oddb::kforwrite);
playertable->add(player);

//create a oddbline object in the modelspace
oddblineptr pline = oddbline::createobject();
pline->setstartpoint(odgepoint3d(100.0,100.0,0.0));
pline->setendpoint(odgepoint3d(200.0,100.0,0.0));
pline->setlayer(player->objectid());
pmodelspace->appendoddbentity(pline);
idmodelspace = pmodelspace->objectid();
}
//repeat
for(int ncount = 0; ncount < 10 ; ncount++)
{
{
if(!idtempmodelspace.isnull())
if(!idtempmodelspace.iserased())
idtempmodelspace.database()->release();
//create a temp database;
oddbdatabaseptr ptempdb = theapp.createdatabase(true, oddb::kmetric);
ptempdb->setinsunits(pdb->getinsunits());
oddbobjectid idowner = ptempdb->getmodelspaceid();

//copy the enities from model space(a single line);
oddbobjectidarray ids;
ids.resize(0);
oddbblocktablerecordptr pmodelspace = idmodelspace.safeopenobject();
oddbobjectiteratorptr psendit = pmodelspace->newiterator();
for (; !psendit->done(); psendit->step()) {
oddbentityptr pent = psendit->entity();
ids.push_back(pent->objectid());
} //for
//copy the enities from the active drawind to the temp drawing;
oddbidmappingptr pmapping = oddbidmapping::createobject();
pmapping->setdestdb(ptempdb);
pdb->wblockcloneobjects(ids,idowner,*pmapping,(oddb::duplicaterecordcloning)oddb::kdrcmanglename,false);
oddbblocktablerecordptr ptempmodelspace = ptempdb->getmodelspaceid().safeopenobject(oddb::kforwrite);
pt3d = ptempmodelspace->origin();
idtempmodelspace = ptempmodelspace->objectid();
//get the enitites from the temp drawing model space
oddbobjectidarray tempids;
tempids.resize(0);
assert(!idtempmodelspace.isnull());
assert(!idtempmodelspace.iserased());
oddbobjectiteratorptr ptempsendit = ptempmodelspace->newiterator();
for (; !ptempsendit->done(); ptempsendit->step()) {
oddbentityptr pent = ptempsendit->entity();
tempids.push_back(pent->objectid());
} //for
//transform the entities from the temp drawing
odgepoint3d ptorigin = odgepoint3d(0.0,0.0,0.0);

odgematrix3d m;
m.settoidentity();
m.settranslation(ptorigin-pt3d);
for(unsigned int i = 0; i < tempids.size(); i++)
{
oddblineptr pline = oddbline::cast(tempids[i].safeopenobject(oddb::kforwrite));
assert(!pline.isnull());
pline->transformby(m);
}
//copy the entities from the temp drawing to the active drawing model space(a single line)
oddbidmappingptr ptempmapping = oddbidmapping::createobject();
oddbobjectid idtempowner = pdb->getmodelspaceid();
ptempmapping->setdestdb(pdb);
ptempmodelspace->database()->wblockcloneobjects(tempids,idtempowner,*ptempmapping,(oddb::duplicaterecordcloning)oddb::kdrcmanglename,false);

//get the entities from the active drawing model space(2 lines)
oddbobjectidarray newids;
newids.resize(0);
oddbobjectiteratorptr pnewsendit = pmodelspace->newiterator();
for (; !pnewsendit->done(); pnewsendit->step()) {
oddbentityptr pent = pnewsendit->entity();
newids.push_back(pent->objectid());
} //for
//remove the copied line from the current drawing
for(unsigned int i = 0; i < newids.size(); i++)
for(unsigned int j = 0; j < ids.size(); j++)
{
if(newids[i] != ids[j]){
oddblineptr plinetodelete= newids[i].safeopenobject(oddb::kforwrite);
plinetodelete->erase(true);
}
}
std::stringstream ss;
ss<<ncount;
::afxmessagebox(ss.str().c_str());
}
}
//the problem is when the code above is executed the application crashes at function wblockcloneobjects(where the entities are copied from temp drawing to the active).
//if oddb::kdrcmanglename parameter is used, it should mangle the dublicated objects with $0(in this case the layertablerecord), but at the 3th iteratiom an error occurs.
}
thanks in advance for any help.
best regards
chudomir
it is a dd bug and it will be fixed in the next maintenance release.
also please note that the oddbidmapping object must be released before the next wblock operation with source database.
code:
oddbidmappingptr pmapping = oddbidmapping::createobject();
pdb->wblockcloneobjects(...);
// ... (custom operation with map or deferred translation)
pmapping = 0;
regards,
sergey vishnevetsky
thanks sergey,
sorry for the pmapping - i was rushing to produce an example quickly. is it possible at some stage that you send me some code if the fix is something short (when you fix it)?
best regards
chudomir
ok, i've sent it.
regards,
sergey vishnevetsky
thanks, i'll try...
best regards
chudomir
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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



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


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