几何尺寸与公差论坛------致力于产品几何量公差标准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-06, 11:37 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】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!
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】error c2664 yang686526 DirectDWG 0 2009-05-05 09:34 AM
【转帖】ambiguous call to overload functions in odstring.h yang686526 DirectDWG 0 2009-05-04 03:56 PM
【转帖】哪位高手指点一下下边lisp的怎么用 yang686526 数据库ObjectDBX 0 2009-04-28 12:13 PM
在vba里由基本三角函数导出的三角函数 yang686526 ObjectARX(AutoLISP) 0 2009-04-26 06:33 PM
哪位高手指点一下下边lisp的怎么用 yang686526 ObjectARX(AutoLISP) 0 2009-04-26 06:19 PM


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


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