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.
Solved! Go to Solution.
Solved by caddzone. Go to Solution.
Solved by Hallex. Go to Solution.
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'~
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.
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.
Hi caddzone,
So, if it's a Autodesk.AutoCAD.Geometry.Curve2d class, then what does the double value refer to?
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.