C3DO-0844 · 261103 legend: remove rows after FENCE [C3D-LGCUT] done
11X17 legend MText 2191D: removes the BOUNDARY LINE, ADJOINER LINE and CENTERLINE rows (everything after FENCE) and erases their three sample lines (2193F, 21940, 2220A).
C# payload
string F(double v)=>v.ToString("0.###");
ObjectId H(string h)=>Db.GetObjectId(false,new Handle(Convert.ToInt64(h,16)),0);
ObjectId Lyr(string name,short c){ var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForRead); if(lt.Has(name)) return lt[name]; lt.UpgradeOpen(); var r=new LayerTableRecord{Name=name,Color=Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci,c)}; var id=lt.Add(r); Tx.AddNewlyCreatedDBObject(r,true); Log("layer created "+name); return id; }
ObjectId Put(BlockTableRecord btr, Autodesk.AutoCAD.DatabaseServices.Entity e, string layer){ e.SetDatabaseDefaults(Db); e.Layer=layer; var id=btr.AppendEntity(e); Tx.AddNewlyCreatedDBObject(e,true); return id; }
var LM=LayoutManager.Current;
BlockTableRecord PS(string name){ var l=(Layout)Tx.GetObject(LM.GetLayoutId(name),OpenMode.ForRead); return (BlockTableRecord)Tx.GetObject(l.BlockTableRecordId,OpenMode.ForWrite); }
var BT=(BlockTable)Tx.GetObject(Db.BlockTableId,OpenMode.ForRead);
var MS=(BlockTableRecord)Tx.GetObject(BT[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
bool HasText(BlockTableRecord btr,string contains){ foreach(ObjectId id in btr){ var o=Tx.GetObject(id,OpenMode.ForRead); if(o is MText m && m.Contents.Contains(contains)) return true; if(o is DBText t && t.TextString.Contains(contains)) return true; } return false; }
// 261103 legend: remove every row after FENCE (BOUNDARY LINE, ADJOINER LINE, CENTERLINE) and their sample lines.
var mt=(MText)Tx.GetObject(H("2191D"),OpenMode.ForWrite);
var rows=mt.Contents.Split(new[]{@"\P"},StringSplitOptions.None).ToList();
int f=rows.FindIndex(r=>r.Trim()=="FENCE");
if(f<0){ Log("STOP - FENCE row not found"); return; }
var gone=rows.Skip(f+1).Select(r=>r.Trim()).ToList();
if(gone.Count==0){ Log("nothing after FENCE - nothing done"); Ed.Regen(); return; }
mt.Contents=string.Join(@"\P",rows.Take(f+1));
Log("rows removed: "+string.Join(", ",gone));
foreach(var h in new[]{"2193F","21940","2220A"}){ var id=H(h); if(id.IsNull||id.IsErased){ Log(h+" already gone"); continue; } var l=(Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id,OpenMode.ForWrite); Log("sample line "+h+" ["+l.Layer+"] erased"); l.Erase(); }
Log("last row now: "+mt.Contents.Split(new[]{@"\P"},StringSplitOptions.None).Last().Trim()+" (verified)");
Ed.Regen();
Result
Log
rows removed: BOUNDARY LINE, ADJOINER LINE, CENTERLINE sample line 2193F [C-PROP-LINE] erased sample line 21940 [V-GIS-PROP-ADJ] erased sample line 2220A [SS-V-ROAD-CNTR] erased last row now: FENCE (verified)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.