Jozi,
This one has been mostly borrowed from one chinese site
and it's a bit tweaky
You can use it as a sketch
- using System;using System.Collections.Generic;using System.Text;using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.Runtime;using System.Collections;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;namespace Join{ public class CurveCommands { [CommandMethod("bins")] public static void Try() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Database db = ed.Document.Database; TypedValue[] ftype = { new TypedValue(0, "LWPOLYLINE") }; PromptSelectionOptions ppo = new PromptSelectionOptions(); ppo.MessageForRemoval = "\nSelected must be polyline only: "; ppo.MessageForAdding = "\nSelect a contour: "; SelectionFilter filter = new SelectionFilter(ftype); PromptSelectionResult res = ed.GetSelection(ppo, filter); if (res.Status != PromptStatus.OK) return; using (Transaction tr = db.TransactionManager.StartTransaction()) { foreach (ObjectId id in res.Value.GetObjectIds()) { Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead); Curve bcurv = (Curve)ent; TypedValue[] ftype2 = { new TypedValue(0, "*LINE,ARC,CIRCLE,ELLIPSE") }; SelectionFilter filter2 = new SelectionFilter(ftype2); PromptSelectionResult pres = ed.SelectAll(filter2); DBObjectCollection objs = new DBObjectCollection(); ObjectId[] ents = pres.Value.GetObjectIds(); foreach (ObjectId nid in ents) { List ptlist = new List(); List dslist = new List(); if (nid != id) { Curve scurv = (Curve)tr.GetObject(nid, OpenMode.ForWrite); Point3dCollection pts = new Point3dCollection(); scurv.IntersectWith(bcurv, Intersect.OnBothOperands, pts, 0, 0); foreach (Point3d p in pts) { ptlist.Add(p); dslist.Add(scurv.GetDistAtPoint(p)); } if (ptlist.Count > 0) { Point3d[] ptarr = ptlist.ToArray(); Array.Sort(dslist.ToArray(), ptarr); try { objs = scurv.GetSplitCurves(new Point3dCollection(ptarr)); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); DBObjectCollection ercol = new DBObjectCollection(); foreach (Curve curv in objs) { btr.AppendEntity(curv); tr.AddNewlyCreatedDBObject(curv, true); Point3d npt = nearestpoint(curv); if ((Fns.IsInsideCurve(bcurv, npt)) && (id != curv.ObjectId)) ercol.Add(curv);//Class Fns is here:http://through-the-interface.typepad.com/through_the_interface/2008/02/robotic-hatchin.html } foreach (DBObject eobj in ercol) { eobj.UpgradeOpen(); eobj.Erase(); eobj.Dispose(); } foreach (ObjectId idx in ents) { if (id != idx) { Entity dent = (Entity)tr.GetObject(idx, OpenMode.ForRead); dent.UpgradeOpen(); dent.Erase(); dent.Dispose(); } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage("\n{0}", ex.Message); } } } } } tr.Commit(); } } public static Point3d nearestpoint(Curve curv) { return curv.GetPointAtDist(0.001); }
~'J'~ |