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

problems in autocad with dwgdirect created polyface meshes
problems in autocad with dwgdirect created polyface meshes
hello, we use dwgdirect 1.12.4 and suffer a serious problem with polyface meshes.
we create a sample polyface mesh in dwgdirect by using this code (taken from the dwgdirect samples):
code:
void codamfcappdoc::appendmeshvertex(oddbpolyfacemesh* pmesh,
double x,
double y,
double z)
{
// create the new vertex.
oddbpolyfacemeshvertexptr pv = oddbpolyfacemeshvertex::createobject();

// add the entity to the polyface mesh.
pmesh->appendvertex(pv);

// set the remaining entity properties.
pv->setposition(odgepoint3d(x, y, z));
}
// append a face record to the passed in polyface mesh entity.
void codamfcappdoc::appendfacerecord(oddbpolyfacemesh* pmesh,
int i1,
int i2,
int i3,
int i4)
{
// create a new face record.
oddbfacerecordptr pfr = oddbfacerecord::createobject();

// add the new entity to the polyface mesh entity.
pmesh->appendfacerecord(pfr);

// set the remaining entity properties.
pfr->setvertexat(0, i1);
pfr->setvertexat(1, i2);
pfr->setvertexat(2, i3);
pfr->setvertexat(3, i4);
}
void codamfcappdoc:ndrawpolyfacemesh()
{
oddbobjectid idlayer;
{
oddbsymboltableptr playertable = database()->getlayertableid().safeopenobject(oddb::kforwrite);
oddblayertablerecordptr player = oddblayertablerecord::createobject();
player->setname("layer1");
idlayer = playertable->add(player);
}
oddbpolyfacemeshptr pmesh = oddbpolyfacemesh::createobject();

// add the new entity to the model space block.
oddbblocktablerecordptr pmodelspace = database()->getmodelspaceid().safeopenobject(oddb::kforwrite);
pmodelspace->appendoddbentity(pmesh);

pmesh->setlayer(idlayer);
pmesh->setcolorindex(1);
odgepoint3d point(0,0,0);// = m_entityboxes.getcenterbox(0,2);
// set the remaining entity properties. vertices and face records
// can only be added after the mesh has been added to its parent block.

double w = 200;
double h = 100;
//double w = m_entityboxes.getwidth(0,2);
//double h = m_entityboxes.getheight();
w /= 4.0;
h /= 3.0;
appendmeshvertex(pmesh, point.x+w, point.y+0);
appendmeshvertex(pmesh, point.x+0, point.y+0);
appendmeshvertex(pmesh, point.x-w, point.y+0);
appendmeshvertex(pmesh, point.x-w, point.y-h);
appendmeshvertex(pmesh, point.x+0, point.y-h);
appendmeshvertex(pmesh, point.x+w, point.y-h);

appendfacerecord(pmesh, 1, 2, 5, 6);
appendfacerecord(pmesh, 2, 3, 4, 5);
}
the mesh is created in layer 1.
we save the drawing and open it in autocad 2002.
in autocad i put layer1 to be the active layer and turn off layer 0.
now in autocad you cannot select the polyface mesh. there are other strange behaviours but this is the worst.
is this a dwgdirect bug? if so please give some info of how it can be avoided? we use polyface meshes a lot and we have poor compatibility with acad.
thank you very much for any help.
best regards
chudomir
i think the source of problem is that your mesh and its subentities (vertices and face records) are on different layers. if so both autocad's and dd audit/recover should report it.
sergey slezkin
hi sergey, thank you for your reply.
here is some more info:
this code (as a command in odamfcappdll):
code:
try {

{
// first create a new layer and make it current
oddblayertablerecordptr player = oddblayertablerecord::createobject();
player->setname("layer1");

oddbsymboltableptr ptable = getdocument()->getlayertableid().safeopenobject(oddb::kforwrite);
oddbobjectid idlayer = ptable->add(player);

getdocument()->setclayer(idlayer);
}


{
oddbpolyfacemeshptr pmesh = oddbpolyfacemesh::createobject();

// create the vertices
//
oddbpolyfacemeshvertexptr pvert1 = oddbpolyfacemeshvertex::createobject();
oddbpolyfacemeshvertexptr pvert2 = oddbpolyfacemeshvertex::createobject();
oddbpolyfacemeshvertexptr pvert3 = oddbpolyfacemeshvertex::createobject();
oddbpolyfacemeshvertexptr pvert4 = oddbpolyfacemeshvertex::createobject();

pvert1->setposition(odgepoint3d(0,0,0));
pvert2->setposition(odgepoint3d(10,0,0));
pvert3->setposition(odgepoint3d(10,10,0));
pvert4->setposition(odgepoint3d(0,10,0));

pmesh->appendvertex(pvert1);
pmesh->appendvertex(pvert2);
pmesh->appendvertex(pvert3);
pmesh->appendvertex(pvert4);

// create one face
//
oddbfacerecordptr pface = oddbfacerecord::createobject();
pface->setvertexat(0,1);
pface->setvertexat(1,2);
pface->setvertexat(2,3);
pface->setvertexat(3,4);

pmesh->appendfacerecord(pface);

// add the mesh to the model space
oddbblocktablerecordptr pblock = getdocument()->getmodelspaceid().safeopenobject(oddb::kforwrite);
pblock->appendoddbentity(pmesh);

pmesh->setdatabasedefaults();
}

} catch(oderror& e) {
afxmessagebox(e.description(),mb_iconerror);
} //catch
produces a wrong mesh. see the attached odamfc1.dwg - turn layer 0 to off and you cannot select the mesh anymore.
i try it in autocad 2002. audit does not report any errors.
however this code (the difference is in italic):
code:
try {

{
// first create a new layer and make it current
oddblayertablerecordptr player = oddblayertablerecord::createobject();
player->setname("layer1");

oddbsymboltableptr ptable = getdocument()->getlayertableid().safeopenobject(oddb::kforwrite);
oddbobjectid idlayer = ptable->add(player);

getdocument()->setclayer(idlayer);
}


{
oddbpolyfacemeshptr pmesh = oddbpolyfacemesh::createobject();

// create the vertices
//
oddbpolyfacemeshvertexptr pvert1 = oddbpolyfacemeshvertex::createobject();
oddbpolyfacemeshvertexptr pvert2 = oddbpolyfacemeshvertex::createobject();
oddbpolyfacemeshvertexptr pvert3 = oddbpolyfacemeshvertex::createobject();
oddbpolyfacemeshvertexptr pvert4 = oddbpolyfacemeshvertex::createobject();

pvert1->setposition(odgepoint3d(0,0,0));
pvert2->setposition(odgepoint3d(10,0,0));
pvert3->setposition(odgepoint3d(10,10,0));
pvert4->setposition(odgepoint3d(0,10,0));

pmesh->appendvertex(pvert1);
pmesh->appendvertex(pvert2);
pmesh->appendvertex(pvert3);
pmesh->appendvertex(pvert4);

// create one face
//
oddbfacerecordptr pface = oddbfacerecord::createobject();
pface->setvertexat(0,1);
pface->setvertexat(1,2);
pface->setvertexat(2,3);
pface->setvertexat(3,4);

pmesh->appendfacerecord(pface);

// add the mesh to the model space
oddbblocktablerecordptr pblock = getdocument()->getmodelspaceid().safeopenobject(oddb::kforwrite);
pblock->appendoddbentity(pmesh);

pvert1->setdatabasedefaults();
pvert2->setdatabasedefaults();
pvert3->setdatabasedefaults();
pvert4->setdatabasedefaults();

pface->setdatabasedefaults();

pmesh->setdatabasedefaults();
}

} catch(oderror& e) {
afxmessagebox(e.description(),mb_iconerror);
} //catch
where i call explicitly setdatabasedefaults for the vertices and the face, well, it seems to work.
am i supposed to call setdatabasedefaults for the face and the vertices? i think no - the mesh may be in a different layer - probably i should call copypropertiesfrom.
anyway, do you think it is a standard behaviour? i think it is dwgdirect that should perform these operations and not the client code...
thanks for the help.
best regards
chudomir
sorry, i was wrong saying that polyface mesh subentities must be on the same layer. it's valid situation if faces have different color and layer properties.
but i see the following autocad's behavior if mesh is on layer_1 and faces are on layer 0:
if layer 0 is turned off the mesh is invisible (in ac2000 and 2005).
so you have to set face properties manualy. how - it's your choice (setdatabasedefaults or other methods).
sergey slezkin
ok, i'll set them. but you think that in objectarx i still have to call setdatabasedefaults() both for the mesh and the faces?
if i call the polyfacemesh setlayer function:
setlayer(oddbobjectid newval, bool dosubents = true);
it works properly for subentities, i've tested.
but see a warning from the objectarx documentation:
warning: acdbpolyfacemeshvertex objects contain the acdbentity methods to set the entity properties such as color, layer, and linetype, but vertices are subentities that are supposed to have the same entity properties as the parent polyface mesh. so, using the acdbentity methods within the acdbpolyfacemeshvertex objects to change these properties to values other than those of the parent results in corrupt vertices (which audit can fix).
so with a simple dwgdirect call (setdatabasedefaults) i have an invalid situation? or what about setpropertiesfrom?
i still think setdatabasedefaults should work for subentities too!
but if you have copied objectarx behaviour, then sorry, i can't argue - i'll try to work around it...
thanks.
best regards
chudomir
it appears that in objectarx setdatabasedefaults() works only for newly created (non-database-resident entities). and vertices and face records can be added only to database-resident mesh...
and appendfacerecord() can't alter subentity properties since it's valid situation if they are not equal to mesh's ones.
i think the correct way is to have optional parameter bool dosubentities in setdatabasedefaults() like in other property editing functions like setcolor(), setlayer(), ... and setpropertiesfrom().
sergey slezkin
ah, thanks, that would be great!
best regards
chudomir
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】numerous link errors on macosx 9xcode 2.50 yang686526 DirectDWG 0 2009-05-06 06:43 PM
【转帖】created drawing crashes autocad yang686526 DirectDWG 0 2009-05-04 06:43 PM
【转帖】使用.net在在文档状态栏实现文档标签控件功能 - 精华帖集合 yang686526 ObjectARX(VB.NET/C#) 0 2009-04-29 05:17 PM
【转帖】[翻译] metaprogramming with autocad (二) - 精华帖集合 yang686526 ObjectARX(VB.NET/C#) 0 2009-04-29 05:02 PM
【转帖】autocad arx 学习笔记(一)(转载) yang686526 ObjectARX(C++) 0 2009-04-16 09:12 AM


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


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