CONNECT C# - How to revolve a shape?

Hello,

I try to follow the recomendations from Jan and Jon to use the .NET API for CONNECT AddIn development instead trying to call mdlSolid_... functions from C# directly

  see: https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/186313/problem-with-smartsolid-solidunion-and-smartsolid-solidsubtract

I used the following code so far to create a revolutional solid:

var elmDscrIn = Shape.MdlElementDescrP(false);
var elmDscrOut = MdlPointerType.Init;
BCOM.Point3d pointOfRotation = Point3d.Origin;

// Revolve always about Y axis
var status = MdlSurfaceRevolve(ref elmDscrOut, elmDscrIn, ref pointOfRotation, (int)Axes.yAxis, RevolutionAngle);
Bentley.DgnPlatformNET.Elements.Element oTorus = null;
if (status == 0 && elmDscrOut != 0)
{
oTorus = ComApp.MdlCreateElementFromElementDescrP(elmDscrOut);
if (oTorus != null)

I use the following code now to create Circular Torus :

DPoint3d center = data.Arc.Anchor.Position.ToDPoint3d();
DVector3d vectorX = DVector3d.UnitX;
DVector3d vectorY = DVector3d.UnitY;
double majorRadius = data.Diameter / 2;
double minorRadius = majorRadius;
Angle sweepAngle = Angle.PI;
bool capped = true;
var oCircularTorus = new DgnTorusPipe(center, vectorX, vectorY, majorRadius, minorRadius, sweepAngle, capped);
DgnModel oModel = Session.Instance.GetActiveDgnModel();

var elmCircularTorus = DraftingElementSchema.ToElement(oModel, oCircularTorus, null);

But how can I revolve a shape?

List<DPoint3d> points = new List<DPoint3d>();

points.Add(new DPoint3d(...)); // Fo each edge

DgnModel oModel = Session.Instance.GetActiveDgnModel();
ShapeElement oRectAngle = new ShapeElement(oModel, null, points.ToArray());

...?

Thanks

Norbert

Parents
  • Hi Jan,

    I'm not familar enough with the SDK so far to answer your question.

    I started to learn the .NET API two months ago by my own.

    Simple mdl programming was used so far:

        mdlSurface_project

        mdlSurface_revolve

       ...

    I have to develope an addin that can create our catalogue parts as 3D model. We have a CAD independent catalog that defines the 3D solids that should be created (cylinder, cuboid, dish, ... and also Union and differences). I've not used union and differences in the old mdl code.

    I found this interessting articles "Learning MicroStation Addins Step by Step"

       https://communities.bentley.com/communities/other_communities/bdn_other_communities/f/bdn--/127326/learning-microstation-addins-step-by-step

    which I used to get started and on the other hand the mdl and VBA documentation, because that is much more documented as the .NET API.

    Unfortunatelly that are based on V8i. I didn't know t my starting point that thiis would point me the wrong direction :-(

    But nevertheless it was very good to start with.

    Yongans answer in this thread

    https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/181708/connect-net-curvevector

    pointing to "C:\Program Files\Bentley\MicroStationCONNECTSDK\Documentation\Migration\Workshop\Docs\MicroStationCONNECT_MigrationWorkshop.pptx"

    was also a good source.

    Thanks

    Norbert

  • Hi Norbert,

    at the end, the code to create revolved element (sweeped element in API terminology) is very simple ;-)

    It required to try one blind alley ... I tried to use Convert1.ElementToBody() method, which worked fine, but it creates SmartSolid, not "revolved solid type". It can be treated as acceptable solution, but because in my opinion it was not fully successful try and fortunately I remember I used SolidPrimite class in the past .. once, I tried this class also.. And it's very powerfull:

    ...
    using Bentley.DgnPlatformNET;
    using Bentley.DgnPlatformNET.Elements;
    using Bentley.GeometryNET;
    using Bentley.MstnPlatformNET;
    ...
    
    private SweepElement()
    {
        DgnModel activeModel = Session.Instance.GetActiveDgnModel();
    
        DPoint3d[] vertices = this.GetVertices(); // custom method to construct a shape
        ShapeElement shape = new ShapeElement(activeModel, null, vertices);
        CurveVector curve = shape.GetCurveVector();
    
        DRay3d axis = this.GetAxis(); // custom method to construct axis parallel with Z
        Angle angle = Angle.FromDegrees(60);
    
        DgnRotationalSweepDetail details = new DgnRotationalSweepDetail(curve, axis, angle, true);
        SolidPrimitive primitive = SolidPrimitive.CreateDgnRotationalSweep(details);
        var element = DraftingElementSchema.ToElement(activeModel, primitive, null);
        element.AddToModel();
    }

    How to receive shape element and rotation axis is up to you, but I assume it will be not a problem.

    With regards,

      Jan

    Answer Verified By: Norbert Meier 

  • Hi Jan,

    many thanks for that example. It helped me very much.

    Here is an example from my side that uses a complex shape. Maybe it's helpful for someone else.

            public static void Test2(string unparsed)
            {
                DgnModel activeModel = Session.Instance.GetActiveDgnModel();
    
                // Arc-Definition (required by ArcElement descriptor)
                DEllipse3d arcInfo = DEllipse3d.FromCenterRadiusXY(new DPoint3d(0, 5, 0), 5);
                arcInfo.StartAngle = Angle.FromDegrees(90);
                arcInfo.SweepAngle = Angle.FromDegrees(180);
    
                // Create complex shape with lines and arc
                ComplexShapeElement complexShape = new ComplexShapeElement(activeModel, null);
                complexShape.AddComponentElement(new LineElement(activeModel, null, new DSegment3d(new DPoint3d(0, 0, 0), new DPoint3d(10, 0, 0))));
                complexShape.AddComponentElement(new LineElement(activeModel, null, new DSegment3d(new DPoint3d(10, 0, 0), new DPoint3d(10, 10, 0))));
                complexShape.AddComponentElement(new LineElement(activeModel, null, new DSegment3d(new DPoint3d(10, 10, 0), new DPoint3d(0, 10, 0))));
                complexShape.AddComponentElement(new ArcElement(activeModel, null, arcInfo));
                complexShape.AddComponentComplete();
    
                // Set sweep angle by parameter
                double.TryParse(unparsed, out double degAngle);
                // and make sure angle is set to resolable size
                if (Math.Abs(degAngle) < 10)
                    degAngle = 180;
                Angle angle = Angle.FromDegrees(degAngle);
    
                // Create revolved solid
                CurveVector curve = complexShape.GetCurveVector();
                DRay3d axis = new DRay3d(DPoint3d.FromXYZ(50, 0, 0), DVector3d.UnitY);
                DgnRotationalSweepDetail details = new DgnRotationalSweepDetail(curve, axis, angle, true);
                SolidPrimitive primitive = SolidPrimitive.CreateDgnRotationalSweep(details);
                var element = DraftingElementSchema.ToElement(activeModel, primitive, null);
                // and add it to the model
                element.AddToModel();
            }
    

    Thanks

    Norbert

Reply
  • Hi Jan,

    many thanks for that example. It helped me very much.

    Here is an example from my side that uses a complex shape. Maybe it's helpful for someone else.

            public static void Test2(string unparsed)
            {
                DgnModel activeModel = Session.Instance.GetActiveDgnModel();
    
                // Arc-Definition (required by ArcElement descriptor)
                DEllipse3d arcInfo = DEllipse3d.FromCenterRadiusXY(new DPoint3d(0, 5, 0), 5);
                arcInfo.StartAngle = Angle.FromDegrees(90);
                arcInfo.SweepAngle = Angle.FromDegrees(180);
    
                // Create complex shape with lines and arc
                ComplexShapeElement complexShape = new ComplexShapeElement(activeModel, null);
                complexShape.AddComponentElement(new LineElement(activeModel, null, new DSegment3d(new DPoint3d(0, 0, 0), new DPoint3d(10, 0, 0))));
                complexShape.AddComponentElement(new LineElement(activeModel, null, new DSegment3d(new DPoint3d(10, 0, 0), new DPoint3d(10, 10, 0))));
                complexShape.AddComponentElement(new LineElement(activeModel, null, new DSegment3d(new DPoint3d(10, 10, 0), new DPoint3d(0, 10, 0))));
                complexShape.AddComponentElement(new ArcElement(activeModel, null, arcInfo));
                complexShape.AddComponentComplete();
    
                // Set sweep angle by parameter
                double.TryParse(unparsed, out double degAngle);
                // and make sure angle is set to resolable size
                if (Math.Abs(degAngle) < 10)
                    degAngle = 180;
                Angle angle = Angle.FromDegrees(degAngle);
    
                // Create revolved solid
                CurveVector curve = complexShape.GetCurveVector();
                DRay3d axis = new DRay3d(DPoint3d.FromXYZ(50, 0, 0), DVector3d.UnitY);
                DgnRotationalSweepDetail details = new DgnRotationalSweepDetail(curve, axis, angle, true);
                SolidPrimitive primitive = SolidPrimitive.CreateDgnRotationalSweep(details);
                var element = DraftingElementSchema.ToElement(activeModel, primitive, null);
                // and add it to the model
                element.AddToModel();
            }
    

    Thanks

    Norbert

Children
No Data