各位老师好,为了尝试把复杂形状的面缝合为实体,以一个正六面体为例进行了尝试。在使用SolidUtil::Modify::SewBodies的时候,发现其输出的类型为bvector<ISolidKernelEntityPtr>,而SolidUtil::Convert::BodyToElement的输入类型为ISolidKernelEntityCR ,不知道如何实现把bvector<ISolidKernelEntityPtr>格式转换为ISolidKernelEntityCR ,请老师帮忙指导,谢谢!
具体代码如下: double uorPerMaster = ACTIVEMODEL->GetModelInfoCP()->GetUorPerMeter(); CurveVectorPtr shapeProfile, shapeProfile2, shapeProfile3, shapeProfile4, shapeProfile5, shapeProfile6; bvector<DPoint3d> ptsk1; ptsk1.resize(5); ptsk1[0] = { 0,0,0 }; ptsk1[1] = { 0,10,0 }; ptsk1[2] = { 10,10,0 }; ptsk1[3] = { 10,0,0 }; ptsk1[4] = { 0,0,0 }; shapeProfile = CurveVector::CreateLinear(&ptsk1[0], ptsk1.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub1; DraftingElementSchema::ToElement(eehSub1, *shapeProfile, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub1.AddToModel(); CurveVectorPtr curve1 = ICurvePathQuery::ElementToCurveVector(eehSub1); bvector<DPoint3d> ptsk2; ptsk2.resize(5); ptsk2[0] = { 0,0,0 }; ptsk2[1] = { 0,10,0 }; ptsk2[2] = { 0,10,-10 }; ptsk2[3] = { 0,0,-10 }; ptsk2[4] = { 0,0,0 }; shapeProfile2 = CurveVector::CreateLinear(&ptsk2[0], ptsk2.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub2; DraftingElementSchema::ToElement(eehSub2, *shapeProfile2, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub2.AddToModel(); CurveVectorPtr curve2 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk3; ptsk3.resize(5); ptsk3[0] = { 0,0,0 }; ptsk3[1] = { 0,10,0 }; ptsk3[2] = { 0,10,-10 }; ptsk3[3] = { 0,0,-10 }; ptsk3[4] = { 0,0,0 }; shapeProfile3 = CurveVector::CreateLinear(&ptsk3[0], ptsk3.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub3; DraftingElementSchema::ToElement(eehSub3, *shapeProfile3, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub2.AddToModel(); CurveVectorPtr curve3 = ICurvePathQuery::ElementToCurveVector(eehSub3); bvector<DPoint3d> ptsk4; ptsk4.resize(5); ptsk4[0] = { 10,0,0 }; ptsk4[1] = { 10,10,0 }; ptsk4[2] = { 10,10,-10 }; ptsk4[3] = { 10,0,-10 }; ptsk4[4] = { 10,0,0 }; shapeProfile4 = CurveVector::CreateLinear(&ptsk4[0], ptsk4.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub4; DraftingElementSchema::ToElement(eehSub4, *shapeProfile4, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub4.AddToModel(); CurveVectorPtr curve4 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk5; ptsk5.resize(5); ptsk5[0] = { 0,10,0 }; ptsk5[1] = { 10,10,0 }; ptsk5[2] = { 10,10,-10 }; ptsk5[3] = { 0,10,-10 }; ptsk5[4] = { 0,10,0 }; shapeProfile5 = CurveVector::CreateLinear(&ptsk5[0], ptsk5.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub5; DraftingElementSchema::ToElement(eehSub5, *shapeProfile5, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub5.AddToModel(); CurveVectorPtr curve5 = ICurvePathQuery::ElementToCurveVector(eehSub5); bvector<DPoint3d> ptsk6; ptsk6.resize(5); ptsk6[0] = { 0,0,0 }; ptsk6[1] = { 10,0,0 }; ptsk6[2] = { 10,0,-10 }; ptsk6[3] = { 0,0,-10 }; ptsk6[4] = { 0,0,0 }; shapeProfile6 = CurveVector::CreateLinear(&ptsk6[0], ptsk6.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub6; DraftingElementSchema::ToElement(eehSub6, *shapeProfile6, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub6.AddToModel(); CurveVectorPtr curve6 = ICurvePathQuery::ElementToCurveVector(eehSub6); ISolidKernelEntityPtr body[6]; if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[0], *curve1,*ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[1], *curve2, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[2], *curve3, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[3], *curve4, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[4], *curve5, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[5], *curve6, *ACTIVEMODEL)) { return; } bvector<ISolidKernelEntityPtr> Ybody, Nbody; if (SUCCESS != SolidUtil::Modify::SewBodies(Ybody, Nbody, body, 6, 0.001, 1)) { return; }; DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); if (Ybody[0].IsValid()) { EditElementHandle eeh; if (SUCCESS != SolidUtil::Convert::BodyToElement(eeh, *Ybody[0], nullptr, *pActiveModel))//此处不知如何处理 { return; } eeh.AddToModel(); };
double uorPerMaster = ACTIVEMODEL->GetModelInfoCP()->GetUorPerMeter(); CurveVectorPtr shapeProfile, shapeProfile2, shapeProfile3, shapeProfile4, shapeProfile5, shapeProfile6; bvector<DPoint3d> ptsk1; ptsk1.resize(5); ptsk1[0] = { 0,0,0 }; ptsk1[1] = { 0,10,0 }; ptsk1[2] = { 10,10,0 }; ptsk1[3] = { 10,0,0 }; ptsk1[4] = { 0,0,0 }; shapeProfile = CurveVector::CreateLinear(&ptsk1[0], ptsk1.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub1; DraftingElementSchema::ToElement(eehSub1, *shapeProfile, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub1.AddToModel(); CurveVectorPtr curve1 = ICurvePathQuery::ElementToCurveVector(eehSub1); bvector<DPoint3d> ptsk2; ptsk2.resize(5); ptsk2[0] = { 0,0,0 }; ptsk2[1] = { 0,10,0 }; ptsk2[2] = { 0,10,-10 }; ptsk2[3] = { 0,0,-10 }; ptsk2[4] = { 0,0,0 }; shapeProfile2 = CurveVector::CreateLinear(&ptsk2[0], ptsk2.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub2; DraftingElementSchema::ToElement(eehSub2, *shapeProfile2, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub2.AddToModel(); CurveVectorPtr curve2 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk3; ptsk3.resize(5); ptsk3[0] = { 0,0,0 }; ptsk3[1] = { 0,10,0 }; ptsk3[2] = { 0,10,-10 }; ptsk3[3] = { 0,0,-10 }; ptsk3[4] = { 0,0,0 }; shapeProfile3 = CurveVector::CreateLinear(&ptsk3[0], ptsk3.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub3; DraftingElementSchema::ToElement(eehSub3, *shapeProfile3, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub2.AddToModel(); CurveVectorPtr curve3 = ICurvePathQuery::ElementToCurveVector(eehSub3); bvector<DPoint3d> ptsk4; ptsk4.resize(5); ptsk4[0] = { 10,0,0 }; ptsk4[1] = { 10,10,0 }; ptsk4[2] = { 10,10,-10 }; ptsk4[3] = { 10,0,-10 }; ptsk4[4] = { 10,0,0 }; shapeProfile4 = CurveVector::CreateLinear(&ptsk4[0], ptsk4.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub4; DraftingElementSchema::ToElement(eehSub4, *shapeProfile4, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub4.AddToModel(); CurveVectorPtr curve4 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk5; ptsk5.resize(5); ptsk5[0] = { 0,10,0 }; ptsk5[1] = { 10,10,0 }; ptsk5[2] = { 10,10,-10 }; ptsk5[3] = { 0,10,-10 }; ptsk5[4] = { 0,10,0 }; shapeProfile5 = CurveVector::CreateLinear(&ptsk5[0], ptsk5.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub5; DraftingElementSchema::ToElement(eehSub5, *shapeProfile5, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub5.AddToModel(); CurveVectorPtr curve5 = ICurvePathQuery::ElementToCurveVector(eehSub5); bvector<DPoint3d> ptsk6; ptsk6.resize(5); ptsk6[0] = { 0,0,0 }; ptsk6[1] = { 10,0,0 }; ptsk6[2] = { 10,0,-10 }; ptsk6[3] = { 0,0,-10 }; ptsk6[4] = { 0,0,0 }; shapeProfile6 = CurveVector::CreateLinear(&ptsk6[0], ptsk6.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub6; DraftingElementSchema::ToElement(eehSub6, *shapeProfile6, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); eehSub6.AddToModel(); CurveVectorPtr curve6 = ICurvePathQuery::ElementToCurveVector(eehSub6); ISolidKernelEntityPtr body[6]; if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[0], *curve1,*ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[1], *curve2, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[2], *curve3, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[3], *curve4, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[4], *curve5, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[5], *curve6, *ACTIVEMODEL)) { return; } bvector<ISolidKernelEntityPtr> Ybody, Nbody; if (SUCCESS != SolidUtil::Modify::SewBodies(Ybody, Nbody, body, 6, 0.001, 1)) { return; }; DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); if (Ybody[0].IsValid()) { EditElementHandle eeh; if (SUCCESS != SolidUtil::Convert::BodyToElement(eeh, *Ybody[0], nullptr, *pActiveModel))//此处不知如何处理 { return; } eeh.AddToModel(); };
bvector<ISolidKernelEntityPtr> bodys;
遍历该容器,for (ISolidKernelEntityPtr body : bodys)
在for循环里面执行类似这个:BentleyStatus nStatus = SolidUtil::Convert::BodyToElement(sweepEh, *body.get(), nullptr, *ACTIVEMODEL);
也就是*body.get()就是您想要的。
Answer Verified By: yuan kong
老师好,按照您的意见修改了代码,在SolidUtil::Convert::BodyToElement这句命令时出现报错,麻烦您看看是否我的使用过程还存在问题?谢谢!
CurveVectorPtr shapeProfile, shapeProfile2, shapeProfile3, shapeProfile4, shapeProfile5, shapeProfile6; bvector<DPoint3d> ptsk1; ptsk1.resize(5); ptsk1[0] = { 0,0,0 }; ptsk1[1] = { 0,10,0 }; ptsk1[2] = { 10,10,0 }; ptsk1[3] = { 10,0,0 }; ptsk1[4] = { 0,0,0 }; shapeProfile = CurveVector::CreateLinear(&ptsk1[0], ptsk1.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub1; DraftingElementSchema::ToElement(eehSub1, *shapeProfile, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub1.AddToModel(); CurveVectorPtr curve1 = ICurvePathQuery::ElementToCurveVector(eehSub1); bvector<DPoint3d> ptsk2; ptsk2.resize(5); ptsk2[0] = { 0,0,-10 }; ptsk2[1] = { 0,10,-10 }; ptsk2[2] = { 10,10,-10 }; ptsk2[3] = { 10,0,-10 }; ptsk2[4] = { 0,0,-10 }; shapeProfile2 = CurveVector::CreateLinear(&ptsk2[0], ptsk2.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub2; DraftingElementSchema::ToElement(eehSub2, *shapeProfile2, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub2.AddToModel(); CurveVectorPtr curve2 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk3; ptsk3.resize(5); ptsk3[0] = { 0,0,0 }; ptsk3[1] = { 0,10,0 }; ptsk3[2] = { 0,10,-10 }; ptsk3[3] = { 0,0,-10 }; ptsk3[4] = { 0,0,0 }; shapeProfile3 = CurveVector::CreateLinear(&ptsk3[0], ptsk3.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub3; DraftingElementSchema::ToElement(eehSub3, *shapeProfile3, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub3.AddToModel(); CurveVectorPtr curve3 = ICurvePathQuery::ElementToCurveVector(eehSub3); bvector<DPoint3d> ptsk4; ptsk4.resize(5); ptsk4[0] = { 10,0,0 }; ptsk4[1] = { 10,10,0 }; ptsk4[2] = { 10,10,-10 }; ptsk4[3] = { 10,0,-10 }; ptsk4[4] = { 10,0,0 }; shapeProfile4 = CurveVector::CreateLinear(&ptsk4[0], ptsk4.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub4; DraftingElementSchema::ToElement(eehSub4, *shapeProfile4, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub4.AddToModel(); CurveVectorPtr curve4 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk5; ptsk5.resize(5); ptsk5[0] = { 0,10,0 }; ptsk5[1] = { 10,10,0 }; ptsk5[2] = { 10,10,-10 }; ptsk5[3] = { 0,10,-10 }; ptsk5[4] = { 0,10,0 }; shapeProfile5 = CurveVector::CreateLinear(&ptsk5[0], ptsk5.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub5; DraftingElementSchema::ToElement(eehSub5, *shapeProfile5, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub5.AddToModel(); CurveVectorPtr curve5 = ICurvePathQuery::ElementToCurveVector(eehSub5); bvector<DPoint3d> ptsk6; ptsk6.resize(5); ptsk6[0] = { 0,0,0 }; ptsk6[1] = { 10,0,0 }; ptsk6[2] = { 10,0,-10 }; ptsk6[3] = { 0,0,-10 }; ptsk6[4] = { 0,0,0 }; shapeProfile6 = CurveVector::CreateLinear(&ptsk6[0], ptsk6.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub6; DraftingElementSchema::ToElement(eehSub6, *shapeProfile6, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub6.AddToModel(); CurveVectorPtr curve6 = ICurvePathQuery::ElementToCurveVector(eehSub6); ISolidKernelEntityPtr body[6]; if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[0], *curve1,*ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[1], *curve2, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[2], *curve3, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[3], *curve4, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[4], *curve5, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[5], *curve6, *ACTIVEMODEL)) { return; } bvector<ISolidKernelEntityPtr> Ybody, Nbody; if (SUCCESS != SolidUtil::Modify::SewBodies(Ybody, Nbody, body, 6, 0.001, 1)) { return; }; DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); EditElementHandle eeh; if (Ybody.size() != 0) { for (ISolidKernelEntityPtr ybody : Ybody) { if (SUCCESS != SolidUtil::Convert::BodyToElement(eeh, *ybody.get(), nullptr, *ACTIVEMODEL))//此处报错 { return; } eeh.AddToModel(); } } if (Nbody.size() != 0) { for (ISolidKernelEntityPtr nbody : Nbody) { if (SUCCESS != SolidUtil::Convert::BodyToElement(eeh, *nbody.get(), nullptr, *ACTIVEMODEL)) { return; } eeh.AddToModel(); } }
抱歉,没有仔细看清您的需求,您试试下面的方法,应该没问题的,如果还是有问题,估计是您MS的版本比较旧,您跟您同事的MS对比下,看看:
CurveVectorPtr shapeProfile, shapeProfile2, shapeProfile3, shapeProfile4, shapeProfile5, shapeProfile6; bvector<DPoint3d> ptsk1; ptsk1.resize(5); ptsk1[0] = { 0,0,0 }; ptsk1[1] = { 0,10,0 }; ptsk1[2] = { 10,10,0 }; ptsk1[3] = { 10,0,0 }; ptsk1[4] = { 0,0,0 }; shapeProfile = CurveVector::CreateLinear(&ptsk1[0], ptsk1.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub1; DraftingElementSchema::ToElement(eehSub1, *shapeProfile, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub1.AddToModel(); CurveVectorPtr curve1 = ICurvePathQuery::ElementToCurveVector(eehSub1); bvector<DPoint3d> ptsk2; ptsk2.resize(5); ptsk2[0] = { 0,0,-10 }; ptsk2[1] = { 0,10,-10 }; ptsk2[2] = { 10,10,-10 }; ptsk2[3] = { 10,0,-10 }; ptsk2[4] = { 0,0,-10 }; shapeProfile2 = CurveVector::CreateLinear(&ptsk2[0], ptsk2.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub2; DraftingElementSchema::ToElement(eehSub2, *shapeProfile2, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub2.AddToModel(); CurveVectorPtr curve2 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk3; ptsk3.resize(5); ptsk3[0] = { 0,0,0 }; ptsk3[1] = { 0,10,0 }; ptsk3[2] = { 0,10,-10 }; ptsk3[3] = { 0,0,-10 }; ptsk3[4] = { 0,0,0 }; shapeProfile3 = CurveVector::CreateLinear(&ptsk3[0], ptsk3.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub3; DraftingElementSchema::ToElement(eehSub3, *shapeProfile3, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub3.AddToModel(); CurveVectorPtr curve3 = ICurvePathQuery::ElementToCurveVector(eehSub3); bvector<DPoint3d> ptsk4; ptsk4.resize(5); ptsk4[0] = { 10,0,0 }; ptsk4[1] = { 10,10,0 }; ptsk4[2] = { 10,10,-10 }; ptsk4[3] = { 10,0,-10 }; ptsk4[4] = { 10,0,0 }; shapeProfile4 = CurveVector::CreateLinear(&ptsk4[0], ptsk4.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub4; DraftingElementSchema::ToElement(eehSub4, *shapeProfile4, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub4.AddToModel(); CurveVectorPtr curve4 = ICurvePathQuery::ElementToCurveVector(eehSub2); bvector<DPoint3d> ptsk5; ptsk5.resize(5); ptsk5[0] = { 0,10,0 }; ptsk5[1] = { 10,10,0 }; ptsk5[2] = { 10,10,-10 }; ptsk5[3] = { 0,10,-10 }; ptsk5[4] = { 0,10,0 }; shapeProfile5 = CurveVector::CreateLinear(&ptsk5[0], ptsk5.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub5; DraftingElementSchema::ToElement(eehSub5, *shapeProfile5, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub5.AddToModel(); CurveVectorPtr curve5 = ICurvePathQuery::ElementToCurveVector(eehSub5); bvector<DPoint3d> ptsk6; ptsk6.resize(5); ptsk6[0] = { 0,0,0 }; ptsk6[1] = { 10,0,0 }; ptsk6[2] = { 10,0,-10 }; ptsk6[3] = { 0,0,-10 }; ptsk6[4] = { 0,0,0 }; shapeProfile6 = CurveVector::CreateLinear(&ptsk6[0], ptsk6.size(), true ? CurveVector::BOUNDARY_TYPE_Outer : CurveVector::BOUNDARY_TYPE_Open); EditElementHandle eehSub6; DraftingElementSchema::ToElement(eehSub6, *shapeProfile6, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL); //eehSub6.AddToModel(); CurveVectorPtr curve6 = ICurvePathQuery::ElementToCurveVector(eehSub6); ISolidKernelEntityPtr body[6]; if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[0], *curve1,*ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[1], *curve2, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[2], *curve3, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[3], *curve4, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[4], *curve5, *ACTIVEMODEL)) { return; } if (SUCCESS != SolidUtil::Create::BodyFromCurveVector(body[5], *curve6, *ACTIVEMODEL)) { return; } bvector<ISolidKernelEntityPtr> Ybody, Nbody; if (SUCCESS != SolidUtil::Modify::SewBodies(Ybody, Nbody, body, 6, 0.001, 1)) { return; }; DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); //修改 ISolidKernelEntityPtr srcSolid; srcSolid = Ybody.front(); EditElementHandle eehEx; BentleyStatus status = SolidUtil::Convert::BodyToElement(eehEx, *srcSolid, nullptr, *ACTIVEMODEL); if (BentleyStatus::SUCCESS == status) { eehEx.AddToModel(); }
老师好,我把这段程序中的其他不相关语句都删除了,发现就可以,可能是与前面的其他语句冲突了。您给的两种方法都满足要求,十分感谢。此外我发现自己语句中有一句应改为CurveVectorPtr curve4 = ICurvePathQuery::ElementToCurveVector(eehSub4);