Hi All,
As above Subject. How can i determine "StartPoint" top of polyline. i have attach image:
Hinh 1.png
When i change UCS:
Hinh2.png
Thanks everybody.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
may be you can get some inspiration from this:
public class Commands { [CommandMethod("Test")] public void Test() { Document doc = AcAp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptEntityOptions opts = new PromptEntityOptions("\nSelect a polyline: "); opts.SetRejectMessage("Not a polyline."); opts.AddAllowedClass(typeof(Polyline), true); PromptEntityResult per = ed.GetEntity(opts); if (per.Status != PromptStatus.OK) return; using (Transaction tr = db.TransactionManager.StartTransaction()) { Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForWrite); pline.SetLowerLeftAboutUcsAsStartPoint(); tr.Commit(); } } private void SetLowerLeftAboutUcsAsStartPoint(Polyline pline) { for (int i = 0; i < GetUcsLowerLeftIndex(pline); i++) { PermuteVertices(pline); } } private int GetUcsLowerLeftIndex(Polyline pline) { Editor ed = AcAp.DocumentManager.MdiActiveDocument.Editor; Matrix3d ucs = ed.CurrentUserCoordinateSystem; Extents3d bbox = pline.GeometricExtents; bbox.TransformBy(ucs); Point3d minPt = bbox.MinPoint; int index = 0; double distance = minPt.DistanceTo(pline.GetPoint3dAt(0).TransformBy(ucs)); if (distance == 0.0) return 0; for (int i = 1; i < pline.NumberOfVertices; i++) { double d = minPt.DistanceTo(pline.GetPoint3dAt(i).TransformBy(ucs)); if (distance == 0.0) return i; if (d < distance) { distance = d; index = i; } } return index; } private void PermuteVertices(Polyline pline) { int lastIndex = pline.NumberOfVertices - 1; Point2d pt = pline.GetPoint2dAt(0); double bulge = pline.GetBulgeAt(0); double startWidth = pline.GetStartWidthAt(0); double endWidth = pline.GetEndWidthAt(0); for (int i = 0; i < lastIndex; i++) { pline.SetPointAt(i, pline.GetPoint2dAt(i + 1)); pline.SetBulgeAt(i, pline.GetBulgeAt(i + 1)); pline.SetStartWidthAt(i, pline.GetStartWidthAt(i + 1)); pline.SetEndWidthAt(i, pline.GetEndWidthAt(i + 1)); } pline.SetPointAt(lastIndex, pt); pline.SetBulgeAt(lastIndex, bulge); pline.SetStartWidthAt(lastIndex, startWidth); pline.SetEndWidthAt(lastIndex, endWidth); } }
Hi _gile,
I just have met 1 mistake when i used your code.This is.
- The first when i didn't change UCS. My StartPoint is ok.
h2.png
- The second when i changed UCS. My StartPoint is not correct.
h1.png
Thank for your help.
Can't find what you're looking for? Ask the community or share your knowledge.