← Inbox

C3DO-0770 · 261101: legend - add SBUC [C3D-LEGEND5] error

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).

Script file
C3DO-0770.cs
Target
261101 - 5491 Roswell Rd NE R2.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

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; 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

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\261101 - Project\261101 - 5491 Roswell Rd NE R2.dwg
Message
new line not found after edit (wrapped?)
Entities
—
Duration
440 ms
Civil 3D
25.0.0.0

Notes

What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.

No notes yet.