试着写了个简单的代码,就是根据两个圆界面和一根导向线用 BodyFromLoft放样生成实体,总是不成功。
麻烦老师帮忙看一下错在哪里?代码如下:
void createLoftSolid(WCharCP /*unparsed*/) { DPoint3d basePt1, basePt2; basePt1 = basePt1.From(0, 0, 0); basePt2 = basePt2.From(0, 0, 500); //构建要放样的两个圆截面 DPoint3d normal; normal = normal.From(0.0, 0.0, 1.0); DEllipse3d circle1, circle2; circle1.InitFromCenterNormalRadius(basePt1, (DVec3dCR)normal, 500); circle2.InitFromCenterNormalRadius(basePt2, (DVec3dCR)normal, 300); //构建放样的导向线 DPoint3d Pts[2]; Pts[0].x = 500; Pts[0].y = 0; Pts[0].z = 0; Pts[1].x = 300; Pts[1].y = 0; Pts[1].z = 500; bvector<DPoint3d> LinePts; LinePts.push_back(Pts[0]); LinePts.push_back(Pts[1]); ICurvePrimitivePtr GuideLinePtr = ICurvePrimitive::CreateLineString(LinePts); CurveVectorPtr GuideLineVectorPtr = CurveVector::Create(CurveVector::BOUNDARY_TYPE_Open); GuideLineVectorPtr->push_back(GuideLinePtr); ICurvePrimitivePtr pCirclePtr1 = ICurvePrimitive::CreateArc(circle1); ICurvePrimitivePtr pCirclePtr2 = ICurvePrimitive::CreateArc(circle2); CurveVectorPtr ArcVectorPtr = CurveVector::Create(CurveVector::BOUNDARY_TYPE_None); ArcVectorPtr->Add(pCirclePtr1); ArcVectorPtr->Add(pCirclePtr2); ISolidKernelEntityPtr loftSolid; EditElementHandle loftSolidEEh; //根据两个圆截面及导向线进行放样生成实体 if (SUCCESS == SolidUtil::Create::BodyFromLoft(loftSolid, &ArcVectorPtr, ArcVectorPtr->size(), &GuideLineVectorPtr, GuideLineVectorPtr->size(), *ACTIVEMODEL,true, false)) { Bentley::DgnPlatform::DraftingElementSchema::ToElement(loftSolidEEh, *loftSolid, nullptr, *ACTIVEMODEL); loftSolidEEh.AddToModel(); } }
① 先把你创建的两个Profile和一个GuideLine添加到模型中查看一下是否创建正确;
②BodyFromLoft的倒二参数periodic应该设置为false吧?该参数的意思是你是否要创建一个封闭的(循环的)Loft?即首截面也是尾截面这样的一个封闭体。
(1) 两个Profile圆弧线和一个GuideLine在图中画出来都没问题.
(2) 倒数第二个参数改为false还是创建不成功。
另外,在ce里用自带的loft工具对这两个圆弧线和导向线创建放样曲面倒是能成功.
管工:你好!
我之前曾写过一个测试代码是能运行成功的。供你参考。你的代码我看还有一个地方不正确,就是关于BodyFromLoft的第二个参数,它应该是一个CurveVectorPtr的数组,每个分量表达一个截面,而不是像你现在那样将两个截面都加入到一个CurveVector中。
void solidCreate(WCharCP unparsed) { // 1 ---- Prepare Data bvector <DPoint3d> profilePts[3]; profilePts[0].push_back({ -1400000.0, 0.0, 500000.0 }); profilePts[0].push_back({ -1400000.0, 500000.0, -500000.0 }); profilePts[0].push_back({ -1400000.0, -500000.0, -500000.0 }); //profilePts[0].push_back({ -1400000.0, 0.0, 500000.0 }); profilePts[1].push_back({ 0.0, 0.0, 0.0 }); profilePts[1].push_back({ 0, 300000.0, -500000.0 }); profilePts[1].push_back({ 0, -250000.0, -500000.0 }); //profilePts[1].push_back({ 0.0, 0.0, 0.0 }); profilePts[2].push_back({ 1400000.0, 0.0, 500000.0 }); profilePts[2].push_back({ 1400000.0, 500000.0, -500000.0 }); profilePts[2].push_back({ 1400000.0, -500000.0, -500000.0 }); //profilePts[2].push_back({ 1400000.0, 0.0, 500000.0 }); DEllipse3d arcPts; arcPts.InitFromPointsOnArc({ -1400000.0, 0.0, 500000.0 }, { 0, 0, 0 }, { 1400000.0, 0.0, 500000.0 }); // 2 ---- Create CurveVector CurveVectorPtr profileVec[3]; //BOUNDARY_TYPE_Outer is important, it can create a closed profile that further makes a solid instead of a sheet profileVec[0] = CurveVector::CreateLinear(profilePts[0], CurveVector::BOUNDARY_TYPE_Outer); profileVec[1] = CurveVector::CreateLinear(profilePts[1], CurveVector::BOUNDARY_TYPE_Outer); profileVec[2] = CurveVector::CreateLinear(profilePts[2], CurveVector::BOUNDARY_TYPE_Outer); ICurvePrimitivePtr arc = ICurvePrimitive::CreateArc(arcPts); CurveVectorPtr guideVec = CurveVector::Create(CurveVector::BOUNDARY_TYPE_Open); guideVec->Add(arc); // 3 ---- Create Solid by Loft ISolidKernelEntityPtr solid; DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); if (SUCCESS != SolidUtil::Create::BodyFromLoft(solid, profileVec, 3, &guideVec, 1, *pActiveModel, false, true)) { mdlDialog_dmsgsPrint(L"Error in BodyFromLoft"); return; } // 4 ---- Convert Solid to EditElementHandle and add it to model if (solid.IsValid()) { EditElementHandle eeh; SolidUtil::Convert::BodyToElement(eeh, *solid, nullptr, *pActiveModel); //DraftingElementSchema::ToElement(eeh, *solid, nullptr, *pActiveModel); eeh.AddToModel(); } }
Answer Verified By: 管华明
生成的图形如下:
此种情况下guideLine为弧线才有作用,如果不给的话,三个截面间的过渡将会是直线过渡。对于你的情况,其实guideLine参数可忽略。
这例子太给力了。按老师的例子中的写法,建出来了。
如果仅仅是绘制这么一个圆台体的话,可以考虑更简单的ISolidPrimitive::DgnConeDetail。
ISolidPrimitive对象对应于Mstn中的Solid元素类型(Type=18/19),ISolidKernelEntity对象对应于Mstn中的SmartSolid元素类型(Type=2)。有关Mstn中的实体元素,请看如下文章:
https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/18254/solidsmartsolidfeaturesolidparametricsolid