[MSCE] 画一个平面,沿着一个曲线,扫描成一个实体

老师好,我想问一下,SolidUtil::Create::BodyFromSweep(solid, *extrusionVector, *LinePtr, *ACTIVEMODEL, false, true, false);这一句这两个参数*extrusionVector, *LinePtr,用VS2015 编译时提示错误。其中:*extrusionVector,提示:没有与这些操作数匹配的“”*“”运算符,操作数类型为:*Bentley::DVec3d;  而*LinePtr,提示:不存在用户定义的从"Bentley::ICurvePrimitive" 到 "const Bentley::CurveVector" 的适当转换?

我是参照符老师您之前帮一个学生写的一个扫描成体功能的函数SolidUtil::Create::BodyFromSweep传参的。我的代码如下:

void yourFunctionName(WCharCP unparsed)
{
ElementId id = 801;
ElementHandle myArc(id, ACTIVEMODEL);
CurveVectorPtr path = ICurvePathQuery::ElementToCurveVector(myArc);

DPoint3d basePt, pts[6],pt1,pt2, tmpPt;
basePt.x = 3.2*g_1mu; basePt.y = -0.6*g_1mu; basePt.z = -1.2*g_1mu;
pts[0] = basePt;
pts[1].x = pts[0].x; pts[1].y = pts[0].y - g_1mu / 2; pts[1].z = pts[0].z;
pts[2].x = pts[1].x + g_1mu / 2; pts[2].y = pts[1].y; pts[2].z = pts[0].z;
pts[3].x = pts[2].x; pts[3].y = pts[2].y - g_1mu / 2; pts[3].z = pts[0].z;
pts[4].x = pts[3].x + g_1mu / 2; pts[4].y = pts[3].y; pts[4].z = pts[0].z;
pts[5].x = pts[4].x; pts[5].y = pts[0].y; pts[5].z = pts[0].z;
pt1 = pt2 = pts[0]; pt2.z += g_1mu;

CurveVectorPtr SolidProfilePtr = CurveVector::Create(CurveVector::BOUNDARY_TYPE_Outer);
bvector<DPoint3d> SolidProfilePts;

//添加截面点到截面中,注意首尾点一定要闭合,首点要加入两次
SolidProfilePts.push_back(pts[0]);
SolidProfilePts.push_back(pts[1]);
SolidProfilePts.push_back(pts[2]);
SolidProfilePts.push_back(pts[3]);
SolidProfilePts.push_back(pts[4]);
SolidProfilePts.push_back(pts[5]);
SolidProfilePts.push_back(pts[0]);

ICurvePrimitivePtr SolidProfileShape = ICurvePrimitive::CreateLineString(&SolidProfilePts.front(), SolidProfilePts.size());
SolidProfilePtr->Add(SolidProfileShape);

DVec3d extrusionVector = DVec3d::FromStartEnd(pt1, pt2);//DVec3d::FromStartEnd 与 DVec3d::FromStartEndNormalize区别

/*---------------------------------------------------------------------------------*
* 用pts[0]、pt1、pt2三点创建线串
**--------------------------------------------------------------------------------*/
bvector<DPoint3d> LineStringPts;
tmpPt = pts[0];
pts[0] = pt2;
pt2 = tmpPt;
pt1.x = pts[0].x + g_1mu;
pt1.y = pt2.y + g_1mu / 2;
LineStringPts.push_back(pts[0]);
LineStringPts.push_back(pt1);
LineStringPts.push_back(pt2);
ICurvePrimitivePtr LinePtr = ICurvePrimitive::CreateLineString(LineStringPts);

ISolidKernelEntityPtr solid;
EditElementHandle sweepSolid;
SolidUtil::Create::BodyFromSweep(solid, *extrusionVector, *LinePtr, *ACTIVEMODEL, false, true, false);
DraftingElementSchema::ToElement(sweepSolid, *solid, nullptr, *ACTIVEMODEL);
sweepSolid.AddToModel();


}

我想实现的功能是通过一个面沿着一个线串扫描(或者说拉伸)成一个实体,现在用BodyFromSweep函数,出了点问题,麻烦老师帮忙看一下,谢谢

  • BodyFromSweep中的profile和path两个参数都要求是CurveVector类型的,而您的这两个参数给的类型都不正确。

    下面是我以前写过的一个测试代码供您参考。其中path是一个弧,在我的DGN中其ElemID=809,你可以根据你的具体情况修改这个值。profile是一个圆。

    void BodyFromSweepTest()
    {
     ElementId id = 809;
     ElementHandle myArc(id, ACTIVEMODEL);
     CurveVectorPtr path = ICurvePathQuery::ElementToCurveVector(myArc);

     DPoint3d  startPnt, endPnt;
     DVec3d startTangent, endTangent;
     path->at(0)->GetStartEnd(startPnt, endPnt, startTangent, endTangent);
     RotMatrix rMatrix = RotMatrix::From1Vector(startTangent, 2, true);

     EditElementHandle myCircle;
     EllipseHandler::CreateEllipseElement(myCircle, nullptr, startPnt, 100, 100, rMatrix, true, *ACTIVEMODEL);
     CurveVectorPtr profile = ICurvePathQuery::ElementToCurveVector(myCircle);

     ISolidKernelEntityPtr solid;
     EditElementHandle     sweepSolid;
     SolidUtil::Create::BodyFromSweep(solid, *profile, *path, *ACTIVEMODEL, false, true, false);
     DraftingElementSchema::ToElement(sweepSolid, *solid, nullptr, *ACTIVEMODEL);
     sweepSolid.AddToModel();
    }



  • 老师,您好,ICurvePrimitivePtr 类型的值怎么转换为CurveVector类型的啊?

    现在我想把ICurvePrimitivePtr SolidProfileShape 这个变量转换为CurveVector类型的profile;

    把ICurvePrimitivePtr LinePtr  转换为CurveVector类型的path;

    这个有转换函数吗?

  • 查一下CurveVector类的成员函数,其中的静态函数Create就可以。如下: