几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   DirectDWG (http://www.dimcax.com/hust/forumdisplay.php?f=89)
-   -   【转帖】problem with the function inser (http://www.dimcax.com/hust/showthread.php?t=18175)

yang686526 2009-05-06 11:37 PM

【转帖】problem with the function inser
 
problem with the function "insert"
problem with the function "insert"
hello,
i try to copy all a layout into a model space. i made a test to copy all the entities a the paper space and all the entities of model space present in the viewports.
my problem is that the function "insert" crash when i have entities in the paper space and in the model space.
in other case (entities only in paper space or only in model space) it seems to work but i've got this error anyway:
oderror_duplicaterecordname at memory location 0x....
there is my code (it's only a test version):
code:
if (m_pdb->gettilemode()==0)
{
oda_trace(_t("paper layout is active\n"));
try
{
oddbdatabaseptr pdb = m_pdb->appservices()->createdatabase(true, m_pdb->getmeasurement());
odstring tempfilename;
// get an entity iterator on the paper layout
oddbblocktablerecordptr pps = m_pdb->getactivelayoutbtrid().safeopenobject(oddb::kforwrite);
oddbobjectiteratorptr ppsentiter = pps->newiterator();
// get an entity iterator on the model space
oddbblocktablerecordptr pms = m_pdb->getmodelspaceid().safeopenobject(oddb::kforwrite);
oddbobjectiteratorptr pmsentiter = pms->newiterator();
// select all the entities of the paper layout (except viewports)
oddbobjectidarray aobjids;
for (ppsentiter->start(); !ppsentiter->done(); ppsentiter->step())
{
oddbentityptr pent = ppsentiter->entity(oddb::kforwrite);
if (!pent.isnull())
{
if (!pent->iskindof(oddbviewport::desc()))
{
aobjids.push_back(ppsentiter->objectid());
}
}
}
oda_trace1(" nb entities in paper space : %i\n",aobjids.length());
// create a temporary database
oddbdatabaseptr pdbtemp = m_pdb->appservices()->createdatabase(true, m_pdb->getmeasurement());
oddbidmappingptr pmap = oddbidmapping::createobject();
pmap->setdestdb(pdbtemp);
// copy all selected element in model space of the temp database
m_pdb->wblockcloneobjects(aobjids, pdbtemp->getmodelspaceid(), *pmap, oddb::kdrcreplace);
// insert the temp database into the global database
try
{
oda_trace(_t(" insert paper space entities\n"));
odgematrix3d resultmat = odgematrix3d::scaling(1);
pdb->insert(resultmat,pdbtemp);
}
catch (...)
{
oda_trace(_t(" insert failed!\n"));
}
tempfilename.format(_t("c:\\temp\\file_paper.dxf"));
pdbtemp->writefile(tempfilename, oddb::kdxf, oddb::vac15 , false /* generate bitmap */ );
if (!pmsentiter->done())
{
for (ppsentiter->start(); !ppsentiter->done(); ppsentiter->step())
{
oddbentityptr pent = ppsentiter->entity(oddb::kforwrite);
if (!pent.isnull())
{
if (pent->iskindof(oddbviewport::desc()))
{
oddbviewportptr pvp = oddbviewport::cast(pent);
oda_trace1("get entities form viewport %i\n",pvp->number());
if (pvp->number() > 1)
{
odgeextents3d geomextents;
pvp->getgeomextents(geomextents);
odgepoint3d ptvpmax = geomextents.maxpoint();
odgepoint3d ptvpmin = geomextents.minpoint();
odgematrix3d resultmat;
ms2ps(pvp,resultmat);
// select all the entities of the model space include in the current viewport
oddbobjectidarray aobjids2;
for (pmsentiter->start(); !pmsentiter->done(); pmsentiter->step())
{
oddbentityptr pent2 = pmsentiter->entity(oddb::kforwrite);
if (!pent2.isnull())
{
pent2->getgeomextents(geomextents);
odgepoint3d ptmax = geomextents.maxpoint();
odgepoint3d ptmin = geomextents.minpoint();
ptmax.transformby(resultmat);
ptmin.transformby(resultmat);
if (((ptvpmax.x - ptmin.x) >= 0) && ((ptmax.x - ptvpmin.x) >= 0) &&
((ptvpmax.y - ptmin.y) >= 0) && ((ptmax.y - ptvpmin.y) >= 0))
{
aobjids2.push_back(pmsentiter->objectid());
}
}
}
oda_trace1(" nb entities include in this viewport : %i\n",aobjids2.length());
// create a temporary database
oddbdatabaseptr pdbtemp2 = m_pdb->appservices()->createdatabase(true, m_pdb->getmeasurement());
oddbidmappingptr pmap = oddbidmapping::createobject();
pmap->setdestdb(pdbtemp2);
// copy all selected element in model space of the temp database
m_pdb->wblockcloneobjects(aobjids2, pdbtemp2->getmodelspaceid(), *pmap, oddb::kdrcreplace);
tempfilename.format(_t("c:\\temp\\file_%1i.dxf"),pvp->number());
pdbtemp2->writefile(tempfilename, oddb::kdxf, oddb::vac15 , false /* generate bitmap */ );
// insert the temp database into the global database
try
{
oda_trace(_t(" insert model space entities visible in viewport\n"));
pdb->insert(resultmat,pdbtemp2);
}
catch (...)
{
oda_trace(_t(" insert failed!\n"));
}
}
}
}
}
}
tempfilename.format(_t("c:\\temp\\file_final.dxf"));
pdb->writefile(tempfilename, oddb::kdxf, oddb::vac15 , false /* generate bitmap */ );
}
catch (...)
{
oda_trace(_t("error in paper layout modification!\n"));
return;
}
}what did i made wrong? thanks.
and i attach a small exemple file with a layout which work and the other not
i've just seen that if i put my code in the odamfcapp it works. there is still the error oderror_duplicaterecordname but it works.
the problem comes when the file is displayed. if in the odamfcapp you're in the list view then it works but if you're in the vectorized view it crash.
what can i do to avoid this problem, in my program i've got only vectorized view?
and what mean exactly the error oderror_duplicaterecordname?
last edited by darra@cadwork.ch; 4th july 2008 at 03:18 amfff">.
i tried your code in odamfcapp and it seems to work without problems.
duplicaterecordname exception is thrown if an attempt is made to add a symboltablerecord or a dictionary entry with non-unique name.
such exceptions occur inside insert() function for example while adding line type continuos, style standard etc.
but these exceptions are caught and handled inside insert() function.
could you provide exact steps how the crash can be reproduced in odamfcapp? btw, which dd version do you use?
sergey slezkin
thanks for the first answer, sergey.
as i said in my second message, the problem occurs in odamfcapp.exe (version 2.6.1) if in my file you select as active layout "layout ko" and then you vectorize (drirectx or opengl doesn抰 matter) your drawing. then if you call my code you're going to catch a rethrow exception from the function "insert".
i made a try catch so the program is not crashing, you'll get only the trace " insert failed!\n".
code:
try
{
oda_trace(_t(" insert model space entities visible in viewport\n"));
pdb->insert(resultmat,pdbtemp2);
}
catch (...)
{
oda_trace(_t(" insert failed!\n"));
}what is the difference in the database if the file is vectorized or not?
for each database only one idmapping object is allowed to exist at a time. else they interact.
in your code 2 instances of oddbidmapping exist: one created for wblock(ing) of ps entities and one inside the cycle for ms entities.
you can make your code working by assigning zero to the first pmap like below. it will destroy the first idmapping object.
code:
// copy all selected element in model space of the temp database
_pdb->wblockcloneobjects(aobjids, pdbtemp->getmodelspaceid(), *pmap, oddb::kdrcreplace);
pmap = 0;
sergey slezkin
thanks a lot sergey!


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