高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】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
|