各位老师好,我刚开始学习mdlSolid相关命令,有个复杂形状想使用mdlSolid_sewBodies把面缝合为实体。在社区中只找到一个完整的例子,链接如下:https://communities.bentley.com/products/programming/microstation_programming/f/archived-microstation-v8i-programming-forum/74116/creating-kibody-from-shapes/198065#198065
因为上述链接是用V8i版本实现的,我想转换为CE版本,尝试结果不理想,在mdlSolid_bodyToElement这一步总是报错导致MS关闭,想请给位老师帮助看一下我的代码哪里有问题,谢谢!
DgnPlatform::MSElement elem00,elem01, elem02, elem03, elem04, elem05; MSElementDescrP edP00, edP01, edP02, edP03, edP04, edP05; BODY_TAG bodyP = NULL; Transform trans, invTrans, toolTrans; DPoint3d ptsk[5]; int count = 0, i; TAG_ENTITY_LIST *sewnBodyListP = NULL; TAG_ENTITY_LIST *unsewnBodyListP = NULL; TAG_ENTITY_LIST *inputBodyListP = NULL; mdlSolid_listCreate(&sewnBodyListP); mdlSolid_listCreate(&unsewnBodyListP); mdlSolid_listCreate(&inputBodyListP); mdlComplexChain_createHeader(&elem00, 1, 0); mdlElmdscr_new(&edP00, NULL, &elem00); mdlComplexChain_createHeader(&elem01, 1, 0); mdlElmdscr_new(&edP01, NULL, &elem01); mdlComplexChain_createHeader(&elem02, 1, 0); mdlElmdscr_new(&edP02, NULL, &elem02); mdlComplexChain_createHeader(&elem03, 1, 0); mdlElmdscr_new(&edP03, NULL, &elem03); mdlComplexChain_createHeader(&elem04, 1, 0); mdlElmdscr_new(&edP04, NULL, &elem04); mdlComplexChain_createHeader(&elem05, 1, 0); mdlElmdscr_new(&edP05, NULL, &elem05); ptsk[0] = { 0,0,0 }; ptsk[1] = { 0,10,0 }; ptsk[2] = { 10,10,0 }; ptsk[3] = {10,0,0}; ptsk[4] = { 0,0,0 }; mdlLineString_create(&elem00, NULL, ptsk, 5); mdlElmdscr_appendElement(edP00, &elem00); mdlSolid_beginCurrTrans(ACTIVEMODEL); mdlSolid_elementToBody(&bodyP, &trans, edP00, ACTIVEMODEL); mdlSolid_listAdd(inputBodyListP, bodyP); mdlTMatrix_getInverse(&invTrans, &trans);//这几句不太理解,可能未达到预期 ptsk[0] = { 0,0,-10 }; ptsk[1] = { 0,10,-10 }; ptsk[2] = { 10,10,-10 }; ptsk[3] = { 10,0,-10 }; ptsk[4] = {0,0,-10}; mdlLineString_create(&elem01, NULL, ptsk, 5); mdlElmdscr_appendElement(edP01, &elem01); mdlTMatrix_multiply(&toolTrans, &invTrans, &trans);//这几句不太理解,可能未达到预期 mdlSolid_elementToBody(&bodyP, &toolTrans, edP01, ACTIVEMODEL); mdlSolid_applyTransform(bodyP, &toolTrans); mdlSolid_listAdd(inputBodyListP, bodyP); ptsk[0] = { 0,0,0 }; ptsk[1] = { 0,10,0 }; ptsk[2] = { 0,10,-10 }; ptsk[3] = { 0,0,-10 }; ptsk[4] = {0,0,0}; mdlLineString_create(&elem02, NULL, ptsk, 5); mdlElmdscr_appendElement(edP02, &elem02); mdlTMatrix_multiply(&toolTrans, &invTrans, &trans); mdlSolid_elementToBody(&bodyP, &toolTrans, edP02, ACTIVEMODEL); mdlSolid_applyTransform(bodyP, &toolTrans); mdlSolid_listAdd(inputBodyListP, bodyP); ptsk[0] = { 10,0,0 }; ptsk[1] = { 10,10,0 }; ptsk[2] = { 10,10,-10 }; ptsk[3] = {10,0,-10}; ptsk[4] = { 10,0,0 }; mdlLineString_create(&elem03, NULL, ptsk, 5); mdlElmdscr_appendElement(edP03, &elem03); mdlTMatrix_multiply(&toolTrans, &invTrans, &trans); mdlSolid_elementToBody(&bodyP, &toolTrans, edP03, ACTIVEMODEL); mdlSolid_applyTransform(bodyP, &toolTrans); mdlSolid_listAdd(inputBodyListP, bodyP); ptsk[0] = { 0,10,0 }; ptsk[1] = { 10,10,0 }; ptsk[2] = { 10,10,-10 }; ptsk[3] = { 0,10,-10 }; ptsk[4] = { 0,10,0 }; mdlLineString_create(&elem04, NULL, ptsk, 5); mdlElmdscr_appendElement(edP04, &elem04); mdlTMatrix_multiply(&toolTrans, &invTrans, &trans); mdlSolid_elementToBody(&bodyP, &toolTrans, edP04, ACTIVEMODEL); mdlSolid_applyTransform(bodyP, &toolTrans); mdlSolid_listAdd(inputBodyListP, bodyP); ptsk[0] = { 0,0,0 }; ptsk[1] = { 10,0,0 }; ptsk[2] = { 10,0,-10 }; ptsk[3] = { 0,0,-10 }; ptsk[4] = { 0,0,0 }; mdlLineString_create(&elem05, NULL, ptsk, 5); mdlElmdscr_appendElement(edP05, &elem05); mdlTMatrix_multiply(&toolTrans, &invTrans, &trans); mdlSolid_elementToBody(&bodyP, &toolTrans, edP05, ACTIVEMODEL); mdlSolid_applyTransform(bodyP, &toolTrans); mdlSolid_listAdd(inputBodyListP, bodyP); mdlSolid_endCurrTrans(); mdlSolid_listCount(&count, inputBodyListP); MSElementDescrP edP10 = NULL; double gapTolerance = 1.0; StatusInt ret; if (count > 0) { mdlSolid_beginCurrTrans(ACTIVEMODEL); ret = mdlSolid_sewBodies(sewnBodyListP, unsewnBodyListP, inputBodyListP, gapTolerance); mdlSolid_listCount(&count, sewnBodyListP); for (i = 0; i<count; i++) { BODY_TAG bodyP0; mdlSolid_listNthEl(&bodyP0, sewnBodyListP, i); if (mdlSolid_bodyToElement(&edP10, bodyP0, TRUE, -1, -1, SMART_ISO_Auto, NULL, ACTIVEMODEL) == SUCCESS)//此处跳错 { mdlElmdscr_add(edP10); mdlElmdscr_freeAll(&edP10); } mdlSolid_freeBody(bodyP0); } mdlSolid_listCount(&count, unsewnBodyListP); for (i = 0; i<count; i++) { BODY_TAG bodyP1; mdlSolid_listNthEl(&bodyP1, unsewnBodyListP, i); if (mdlSolid_bodyToElement(&edP10, bodyP1, TRUE, -1, -1, SMART_ISO_Auto, NULL, ACTIVEMODEL) == SUCCESS) { mdlElmdscr_add(edP10); mdlElmdscr_freeAll(&edP10); } mdlSolid_freeBody(bodyP1); } mdlSolid_endCurrTrans(); } mdlSolid_listDelete(&sewnBodyListP); mdlSolid_listDelete(&unsewnBodyListP); mdlSolid_listDelete(&inputBodyListP);
个人初步判断可能出错的地方有:
1、原文中采用createBody(&bodyP, &trans, &p1, &p2, &p3, &p4),因未找到此命令,改为先mdlLineString_create,再mdlElmdscr_appendElement,再mdlSolid_elementToBody,多次转换过程可能出错。
2、对Transform trans, invTrans, toolTrans;定义的几个转换的理解不足,导致mdlSolid_sewBodies缝合结果与预期差距较大,可能出错。
3、对mdlSolid_bodyToElement的使用范围和参数理解不够。
因初学,可能代码问题较多,请老师们多多包涵,谢谢!
mdlSolid_beginCurrTrans的调用往前移三行,如下所示:
Answer Verified By: yuan kong
老师好,调整之后报错,追踪错误还是在mdlSolid_bodyToElement处。
老师好,我用的是update10的版本,这里面能看到具体版本信息吗?
能否上传一下您的测试dgn文件
test20200325.dgn老师好,这是我用上述命令生成的文件。我把未缝合的6个面用mdlElmdscr_add添加上来了,但是缝合之后的因为mdlSolid_bodyToElement未成功,就无法显示了
老师好,已在其他同事那里验证确实执行没问题了,但是我这执行就报错,这个可能是SDK或者MS版本的问题吗?
老师好,我把这段程序中的其他不相关语句都删除了,发现就可以,可能是与前面的其他语句冲突了。您给的两种方法都满足要求,十分感谢。