iIn case you've stacked with it, change object names and layer names in filter
public static void BreakLines()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
using (DocumentLock doclock = doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
ed.WriteMessage("\nSelect vertical lines\n");
PromptSelectionResult res = ed.GetSelection(
new PromptSelectionOptions(),
new SelectionFilter(new TypedValue[] { new TypedValue(0, "line"), new TypedValue( (int)DxfCode.LayerName,"grid" )}));
if (res.Status != PromptStatus.OK)
return;
ObjectId[] verIds = res.Value.GetObjectIds();
ed.WriteMessage("\nSelect horizontal polylines");
res = ed.GetSelection(
new PromptSelectionOptions(),
new SelectionFilter(new TypedValue[] { new TypedValue(0, "lwpolyline"), new TypedValue((int)DxfCode.LayerName, "Defpoints") }));
if (res.Status != PromptStatus.OK)
return;
ObjectId[] horIds = res.Value.GetObjectIds();
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
db.CurrentSpaceId,
OpenMode.ForWrite,
false);
for (int i = 0; i < horIds.Length; i++)
{
Polyline lh = (Polyline)tr.GetObject(horIds[i], OpenMode.ForRead);
Curve ch = lh as Curve;
Point3dCollection allpts = new Point3dCollection();
foreach (ObjectId id in verIds)
{
Line lv = (Line)tr.GetObject(id, OpenMode.ForRead);
Curve cv = lv as Curve;
Point3dCollection pts = new Point3dCollection();
ch.IntersectWith(lv, Intersect.OnBothOperands, pts, 0, 0);
if (pts.Count > 0)
{
foreach (Point3d pt in pts)
allpts.Add(pt);
}
}
List<double> lst= new List<double>();
DoubleCollection pars = new DoubleCollection();
foreach (Point3d pt in allpts)
lst.Add(ch.GetParameterAtPoint(pt));
lst.Sort();
foreach (double param in lst)
pars.Add(param);
DBObjectCollection objs = lh.GetSplitCurves(pars);
foreach (DBObject obj in objs)
{
Entity en = obj as Entity;
btr.AppendEntity(en);
tr.AddNewlyCreatedDBObject(en, true);
lh.UpgradeOpen();
lh.Erase();
}
}
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(ex.Message);
}
}
}
}