C3DO-0771 · 261101: legend - add SBUC [C3D-LEGEND5] done
Add 'SBUC SOUTHERN BELL UNDERGROUND CABLE' to the legend text (2191D) after WM WATER METER, and slide the symbol rows and sample lines below down by the measured line shift (found relative to the legend's current location; north arrow excluded).
C# payload
Func<string,ObjectId> oid=hs=>{ ObjectId id; Db.TryGetObjectId(new Handle(Convert.ToInt64(hs,16)),out id); return id; };
Func<MText,Dictionary<string,double>> lines=m=>{ var d=new Dictionary<string,double>(); var c=new DBObjectCollection(); m.Explode(c); foreach(Autodesk.AutoCAD.DatabaseServices.DBObject o in c){ var t=o as DBText; if(t!=null&&!d.ContainsKey(t.TextString.Trim())) d[t.TextString.Trim()]=t.Position.Y; o.Dispose(); } return d; };
var mid=oid("2191D"); if(mid.IsNull||mid.IsErased){ Log("STOP - legend text 2191D not found"); return; }
var mt=(MText)Tx.GetObject(mid,OpenMode.ForWrite);
var sp=(BlockTableRecord)Tx.GetObject(mt.OwnerId,OpenMode.ForRead);
string add="SBUC SOUTHERN BELL UNDERGROUND CABLE";
if(mt.Contents.Contains("SBUC")){ Log("SBUC already in legend - nothing to do"); return; }
var b=lines(mt); double yWM=b["WM WATER METER"], oldDI=b["DROP INLET"], yLast=b.Values.Min();
double xl=mt.Location.X-0.05, xr=mt.Location.X+0.30;
var move=new List<Autodesk.AutoCAD.DatabaseServices.Entity>();
foreach(ObjectId id in sp){ if(id==mid) continue; var e=(Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id,OpenMode.ForRead); if(e is Viewport) continue; if(e.Layer=="BLOCK_NORTH_ARROW") continue;
Extents3d x; try{ x=e.GeometricExtents; }catch{ continue; }
if(x.MinPoint.X>=xl&&x.MaxPoint.X<=xr&&x.MaxPoint.Y<yWM&&x.MinPoint.Y>yLast-0.2) move.Add(e); }
string c0=mt.Contents; string key="WM WATER METER"; int at=c0.IndexOf(key); if(at<0) throw new Exception("WM line not found");
at+=key.Length; double w0=mt.Width; if(w0>0){ mt.Width=0; Log("legend text width "+w0.ToString("F4")+" -> 0 (no wrap; rows are hard breaks)"); } mt.Contents=c0.Substring(0,at)+@"\P"+add+c0.Substring(at);
var a2=lines(mt); if(!a2.ContainsKey(add)) throw new Exception("new line not found after edit (wrapped?)");
double dy=a2["DROP INLET"]-oldDI;
foreach(var e in move){ e.UpgradeOpen(); e.TransformBy(Matrix3d.Displacement(new Vector3d(0,dy,0))); }
Log("added '"+add+"' after WM at y "+a2[add].ToString("F4")+"; moved "+move.Count+" symbol/sample pieces "+dy.ToString("F4")+" (verified: DROP INLET "+oldDI.ToString("F4")+" -> "+a2["DROP INLET"].ToString("F4")+")");
var cb=(BlockReference)Tx.GetObject(oid("2191F"),OpenMode.ForRead); double cbc=(cb.GeometricExtents.MinPoint.Y+cb.GeometricExtents.MaxPoint.Y)/2;
Log("drop inlet symbol center "+cbc.ToString("F4")+" vs DROP INLET baseline+0.045 "+(a2["DROP INLET"]+0.045).ToString("F4"));
Ed.Regen();
Result
Log
legend text width 2.6880 -> 0 (no wrap; rows are hard breaks) added 'SBUC SOUTHERN BELL UNDERGROUND CABLE' after WM at y 12.9859; moved 35 symbol/sample pieces -0.1587 (verified: DROP INLET 12.9859 -> 12.8273) drop inlet symbol center 12.8723 vs DROP INLET baseline+0.045 12.8723
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.