appendoddbentity method error
appendoddbentity method error
plese help me!
i wan't add some entity from a dwg file to another dwg file,but i get the error. "rendering aborted" ?object was permanentlyerased.
the code is:
code:
void cdwgviewer:

ntoolopenm()
{
// todo: add your command handler code here
oddbdatabaseptr pmdb; // a smart pointer to a database
oddbobjectid id;
oddbdatabase* pdb = getdocument()->m_pdb;
cstring spath = theapp.browsewithpreview(getsafehwnd(),
_t("dwg files (*.dwg)|*.dwg|dxf files (*.dxf)|*.dxf|all files (*.*)|*.*||"));
if(spath.getlength())
{
// create a database and load the drawing into it.
pmdb =theapp.readfile(odstring(spath));
}
// open the block table
oddbblocktableptr pblocks =
pmdb->getblocktableid().safeopenobject();
// get an iterator for the block table
oddbsymboltableiteratorptr pblkiter = pblocks->newiterator();
// for each block in the block table
for (pblkiter->start(); ! pblkiter->done(); pblkiter->step())
{
// open the block
oddbblocktablerecordptr pblock =
pblkiter->getrecordid().safeopenobject();
// get an entity iterator
oddbobjectiteratorptr pentiter = pblock->newiterator();
// if (shxtextstyleida.isnull())
// {
// shxtextstyleida = addstylea(pdb, dd_t("odashxstyle"), 0.0, 1.0, 0.2, 0.0, dd_t("hzkt"));
// }
// for each entity in the block
for (; !pentiter->done(); pentiter->step())
{
id=pentiter->objectid();
oddbentityptr pent = id.safeopenobject();
//messagebox(pent->layer(),_t("test"),mb_ok);
if (pent->layer().find(odstring("mackup"))!=-1) {
oddbentityptr pnent = oddbentity::createobject();
pnent=pent->clone();
// oddbblocktablerecordptr pspace = pdb->getactivelayoutbtrid().safeopenobject(oddb::kforwrite);
oddbblocktablerecordptr pspace = pdb->getmodelspaceid().safeopenobject(oddb::kforwrite);
// pnent->setdatabasedefaults(pdb);getmodelspaceid()
pspace->appendoddbentity(pnent);
}
}
}
pmdb.release(); // delete the database before odunitialize() is called.
}
i'm use the 2.20 dd lib
attached images
1. the line below makes no sence. i suppose the null is returned from createobject().
code:
oddbentityptr pnent = oddbentity::createobject();
2. after you get a copy of entity by clone() this entity references objects in the same database as the original one (layer, linetype etc.).
after you append it to another database you have an entity in one drawing which references objects from another. this is incorrect situation.
to copy an entity(ies) from one database to another you need use oddbdatabase::wblockcloneobjects().
sergey slezkin
last edited by mmuratov; 12th february 2007 at 04:35 amfff">.
thank you
thank you!