.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

About the Curve2d.GetSplitCurves method in Geometry namespace

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
stanmoong
3240 Views, 5 Replies

About the Curve2d.GetSplitCurves method in Geometry namespace

I'm looking at the API documentation, and it states that we need to pass in an "input parameter value at which curve is to be split", which is a double data type.

 

What does it mean by input parameter value?

 

Could anyone post a code snippet / pseudocode to illustrate how to use this?

 

Thanks.

5 REPLIES 5
Message 2 of 6
Hallex
in reply to: stanmoong

I think you can use Curve to solve your task instead of Curve2d

See example

 

        [CommandMethod("PPB")]
        //for Discussion forum only
        static public void PlinePlineBreak()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                PromptEntityOptions peo = new PromptEntityOptions("\nSelect First Polyline >>");
                peo.SetRejectMessage("\nSelect polyline only >>");
                peo.AddAllowedClass(typeof(Polyline), false);
                PromptEntityResult res;
                res = ed.GetEntity(peo);
                if (res.Status != PromptStatus.OK)
                    return;
                Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                if (ent == null)
                    return;
                Polyline pline1 = (Polyline)ent as Polyline;
                if (pline1 == null) return;
                peo = new PromptEntityOptions("\nSelect Second Polyline >>");
                peo.SetRejectMessage("\nSelect polyline only >>");
                peo.AddAllowedClass(typeof(Polyline), false);
                res = ed.GetEntity(peo);
                if (res.Status != PromptStatus.OK)
                    return;
                ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                if (ent == null)
                    return;
                Polyline pline2 = (Polyline)ent as Polyline;
                if (pline2 == null) return;

                pline1.UpgradeOpen();

                pline2.UpgradeOpen();

                BlockTableRecord btr =
                    (BlockTableRecord)tr.GetObject(
                        db.CurrentSpaceId,
                        OpenMode.ForWrite,
                        false);

                List<double> pars1 = new List<double>();
                Curve fcurve = (Curve)tr.GetObject(pline1.ObjectId, OpenMode.ForRead);
                List<double> pars2 = new List<double>();
                Curve scurve = (Curve)tr.GetObject(pline2.ObjectId, OpenMode.ForRead);


                Point3dCollection iwpnts = new Point3dCollection();
                fcurve.IntersectWith(scurve, Intersect.OnBothOperands, iwpnts, 0, 0);
                foreach (Point3d p in iwpnts)
                {
                    pars1.Add(fcurve.GetParameterAtPoint(fcurve.GetClosestPointTo(p, false)));
                    pars2.Add(scurve.GetParameterAtPoint(scurve.GetClosestPointTo(p, false)));
                }

                if (pars1.Count == 0) return; if (pars2.Count == 0) return;

                pars1.Sort(); pars2.Sort();
                try
                {

                    foreach (Curve c in fcurve.GetSplitCurves(new DoubleCollection(pars1.ToArray())))
                    {
                        btr.AppendEntity(c);
                        tr.AddNewlyCreatedDBObject(c, true);
                    }
                    foreach (Curve c in scurve.GetSplitCurves(new DoubleCollection(pars2.ToArray())))
                    {
                        btr.AppendEntity(c);
                        tr.AddNewlyCreatedDBObject(c, true);
                    }
                    pline1.Erase(); pline2.Erase(); tr.Commit();

                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message + "\n" + ex.StackTrace);
                }

            }
        }

 

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 6
caddzone
in reply to: stanmoong

A parameter value identifies a point on a curve. What the value means

exactly depends on the type of curve. With a database Curve, If you

know the point, and need the parameter you can pass the point to the

GetParameterAtPoint() method to get the parameter. There should also

be a corresponding method on the abstract curve classes.



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 4 of 6
stanmoong
in reply to: Hallex

Hi hallex,

 

Thanks for the code. I used the Autodesk.AutoCAD.DatabaseServices.Curve for splitting, was just wondering what is the difference between that and the one found in Autodesk.AutoCAD.Geometry.Curve2d class.

Message 5 of 6
stanmoong
in reply to: caddzone

Hi caddzone,

 

So, if it's a Autodesk.AutoCAD.Geometry.Curve2d class, then what does the double value refer to?

Message 6 of 6
stanmoong
in reply to: caddzone

Sorry, I misunderstood your reply. I checked in the API doc and found the Curve2d.GetParameterOf() method, which returns the parameter value.

 

It seems that I need to call this twice to get the line segments on each side of a polygon made of CompositeCurve2d, then form combine it to form new CompositeCurve2d.

 

Would it be advisable instead to use the Database namespace classes?

 

Basically, I need to pre-compute all the necessary vertices or line segments, before drawing using the Database namespace classes.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost