AnsweredAssumed Answered

Create Loft from 2 ellipses (C#)

Question asked by Vadim Vadim on Jul 1, 2015

Hi all. I have some problem. I need to create loft from 2 ellipses. Ellipses was create by this code like curve:

 

        ISldWorks application;

        IModeler modeler = application.IGetModeler();

        List<IBody2> surfs = new List<IBody2>();

        Curve frontEllipse, backEllipse;

        int error = 0;

        Point3D center = new Point3D(0, 0, 0);

        frontEllipse = modeler.CreateEllipse(new double[] { 0, 0, 0 }, 1,1, new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }) as Curve;

        backEllipse = modeler.CreateEllipse(new double[] { 0, 0, 2 }, 1, 1, new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }) as Curve;

 

        surfs.Add(CreateLoftSurface(application, frontEllipse, backEllipse));

        object[] res = (object[])modeler.CreateBodiesFromSheets2(surfs.ToArray(), (int)swSheetSewingOption_e.swSewToSolidOrSheets, 0.0001, ref error);

        IBody2 body = res[0] as IBody2;

 

        public static IBody2 CreateLoftSurface(ISldWorks SwApp, Curve start, Curve end)

        {

            Curve[] profiles = new Curve[2];

            profiles[0] = start.MakeBsplineCurve2();

            profiles[1] = end.MakeBsplineCurve2();

 

            IModeler modeler = SwApp.IGetModeler();

 

            double nStartParam, nEndParam;

            bool bIsClosed, bIsPeriodic;

            start.GetEndParams(out nStartParam, out nEndParam, out bIsClosed, out bIsPeriodic);

 

            double[] vStart1 = (double[])start.Evaluate(nStartParam);

            double[] vEnd1 = (double[])start.Evaluate(nEndParam);

 

            end.GetEndParams(out nStartParam, out nEndParam, out bIsClosed, out bIsPeriodic);

 

            double[] vStart2 = (double[])end.Evaluate(nStartParam);

            double[] vEnd2 = (double[])end.Evaluate(nEndParam);

 

            Curve[] guides = new Curve[2];

            guides[0] = CreateLineBSpline(modeler, new Point3D(vStart1[0], vStart1[1], vStart1[2]), new Point3D(vStart2[0], vStart2[1], vStart2[2]));

            guides[1] = CreateLineBSpline(modeler, new Point3D(vEnd1[0], vEnd1[1], vEnd1[2]), new Point3D(vEnd2[0], vEnd2[1], vEnd2[2]));

 

            Surface surf = modeler.CreateLoftSurface(profiles, false, false, guides, 0, 0,

                             null, null, guides, guides, false, false,

                             null, null, -1, -1, -1, -1) as Surface;

 

            return surf.CreateTrimmedSheet4(new Curve[] { guides[0], profiles[0], guides[1], profiles[1] }, true) as IBody2;

        }

 

 

        private static Curve CreateLineBSpline(IModeler modeler, Point3D p1, Point3D p2)

        {

            double[] prop = new double[] { 4.24399158341274E-314, 9.88131291682493E-324 };

            double[] knot = new double[] { 0, 0, 1, 1 };

            double[] ctrl = new double[] { p1.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z };

            return modeler.CreateBsplineCurve(prop, knot, ctrl) as Curve;

        }

 

It's work, when i use simple lines at start and end curve for loft. But it doesnt work, when i change lines at ellipses. Can someone help me ?

Outcomes