Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
First attempt:
using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; [assembly: CommandClass(typeof(Rivilis.HatchUtils))] namespace Rivilis { public class HatchUtils { [CommandMethod("RHB", CommandFlags.Modal)] public void RHB() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptEntityOptions prOps = new PromptEntityOptions("\nSelect Hatch: "); prOps.SetRejectMessage("\nNot a Hatch"); prOps.AddAllowedClass(typeof(Hatch),false); PromptEntityResult prRes = ed.GetEntity(prOps); if (prRes.Status != PromptStatus.OK) return; using (Transaction tr = doc.TransactionManager.StartTransaction()) { Hatch hatch = tr.GetObject(prRes.ObjectId, OpenMode.ForRead) as Hatch; if (hatch != null) { BlockTableRecord btr = tr.GetObject(hatch.OwnerId, OpenMode.ForWrite) as BlockTableRecord; if (btr == null) return; int nLoops = hatch.NumberOfLoops; for (int i = 0; i < nLoops; i++) { HatchLoop loop = hatch.GetLoopAt(i); if (loop.IsPolyline) { Polyline poly = new Polyline(); int iVertex = 0; foreach (BulgeVertex bv in loop.Polyline) { poly.AddVertexAt(iVertex++, bv.Vertex, bv.Bulge, 0.0, 0.0); } btr.AppendEntity(poly); tr.AddNewlyCreatedDBObject(poly, true); } else { int iCurve = 0; Plane plane = hatch.GetPlane(); foreach (Curve2d cv in loop.Curves) { LineSegment2d l2d = cv as LineSegment2d; CircularArc2d c2d = cv as CircularArc2d; EllipticalArc2d e2d = cv as EllipticalArc2d; NurbCurve2d n2d = cv as NurbCurve2d; if (l2d != null) { Line ent = new Line(); ent.StartPoint = new Point3d(plane, l2d.StartPoint); ent.EndPoint = new Point3d(plane, l2d.EndPoint); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } else if (c2d != null) { if (Math.Abs(c2d.StartAngle - c2d.EndAngle) < 1e-5) { Circle ent = new Circle(new Point3d(plane, c2d.Center), plane.Normal, c2d.Radius); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } else { Arc ent = new Arc(new Point3d(plane, c2d.Center),c2d.Radius,c2d.StartAngle,c2d.EndAngle); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } } else if (e2d != null) { Ellipse ent = new Ellipse(new Point3d(plane, e2d.Center), plane.Normal, new Vector3d(plane,e2d.MajorAxis) * e2d.MajorRadius, e2d.MinorRadius / e2d.MajorRadius, e2d.StartAngle, e2d.EndAngle); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } else if (n2d != null) { if (n2d.HasFitData) { NurbCurve2dFitData n2fd = n2d.FitData; Point3dCollection p3ds = new Point3dCollection(); foreach (Point2d p in n2fd.FitPoints) p3ds.Add(new Point3d(plane,p)); Spline ent = new Spline(p3ds, new Vector3d(plane,n2fd.StartTangent), new Vector3d(plane,n2fd.EndTangent), n2fd.KnotParam, n2fd.Degree, n2fd.FitTolerance.EqualPoint); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } else { NurbCurve2dData n2fd = n2d.DefinitionData; Point3dCollection p3ds = new Point3dCollection(); DoubleCollection knots = new DoubleCollection(n2fd.Knots.Count); foreach (Point2d p in n2fd.ControlPoints) p3ds.Add(new Point3d(plane,p)); foreach (double k in n2fd.Knots) knots.Add(k); double period = 0; Spline ent = new Spline(n2fd.Degree, n2fd.Rational, n2d.IsClosed(), n2d.IsPeriodic(out period), p3ds, knots, n2fd.Weights, n2fd.Knots.Tolerance, n2fd.Knots.Tolerance); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } } } } } } tr.Commit(); } } } }
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
![]() | ![]() |
Solved! Go to Solution.