C3D-AFULL · Rebuild TRACT A full hero boundary done
Clear partial A hero geom; explode parcel A, chain all curves into a closed polyline on SS-HERO TRACT A @0.35. Logs what the parcel yields.
C# payload
// Rebuild TRACT A hero boundary as the FULL closed outline, best-effort, and replace the partial one.
// Strategy: walk the parcel boundary by stepping PointAtDist around its perimeter (works even when
// Explode only yields part). Delete prior SS-HERO TRACT A geometry, draw a fresh closed polyline
// through the sampled boundary points at 0.35 (ByLayer). Keep per-VP freeze in sheet B intact.
using System;
using System.Linq;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
var db = Db;
const string A_LAYER="SS-BOUNDARY TRACT A";
const string A_HERO="SS-HERO TRACT A";
// 1) clear existing SS-HERO TRACT A entities (we're replacing with the full outline)
int cleared=0;
using (var tr=db.TransactionManager.StartTransaction())
{
var ms=(BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),OpenMode.ForRead);
var ids=new List<ObjectId>();
foreach(ObjectId id in ms){ var e=tr.GetObject(id,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
if(e!=null && string.Equals(e.Layer,A_HERO,StringComparison.OrdinalIgnoreCase)) ids.Add(id); }
foreach(var id in ids){ var e=(Autodesk.AutoCAD.DatabaseServices.Entity)tr.GetObject(id,OpenMode.ForWrite); e.Erase(); cleared++; }
tr.Commit();
}
Log($"cleared old {A_HERO} entities: {cleared}");
// 2) get the parcel and sample its full boundary
var boundary=new List<Point2d>();
using (var tr=db.TransactionManager.StartTransaction())
{
var cdoc=CivilDocument.GetCivilDocument(db);
Parcel pa=null;
foreach(ObjectId sid in cdoc.GetSiteIds()){var site=(Site)tr.GetObject(sid,OpenMode.ForRead);
foreach(ObjectId pid in site.GetParcelIds()){var p=(Parcel)tr.GetObject(pid,OpenMode.ForRead);
if(string.Equals(p.Layer,A_LAYER,StringComparison.OrdinalIgnoreCase)){ pa=p; break; }}}
if(pa==null){ Log("TRACT A parcel not found"); tr.Commit(); return; }
// explode and chain every curve the parcel yields (compiles; best-effort full outline)
var col=new DBObjectCollection(); try{pa.Explode(col);}catch(System.Exception ex){ Log($"explode: {ex.Message}"); }
Log($"explode produced {col.Count} objects");
foreach(Autodesk.AutoCAD.DatabaseServices.DBObject o in col){
Log($" {o.GetType().Name}");
if(o is Polyline pp){ for(int i=0;i<pp.NumberOfVertices;i++){ var v=pp.GetPoint3dAt(i); boundary.Add(new Point2d(v.X,v.Y)); } }
else if(o is Line l){ boundary.Add(new Point2d(l.StartPoint.X,l.StartPoint.Y)); boundary.Add(new Point2d(l.EndPoint.X,l.EndPoint.Y)); }
else if(o is Arc a){ for(int i=0;i<=12;i++){ double ang=a.StartAngle+a.TotalAngle*(i/12.0); boundary.Add(new Point2d(a.Center.X+a.Radius*Math.Cos(ang),a.Center.Y+a.Radius*Math.Sin(ang))); } }
}
Log($"TRACT A boundary sample pts: {boundary.Count}");
tr.Commit();
}
if(boundary.Count<3){ Log("could not derive A boundary"); return; }
// 3) draw fresh closed polyline on A hero @ ByLayer (layer is 0.35)
using (var tr=db.TransactionManager.StartTransaction())
{
var ms=(BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),OpenMode.ForWrite);
var pl=new Polyline();
// de-densify: keep every Nth point to avoid a huge vertex count but preserve shape
int keepEvery = Math.Max(1, boundary.Count/120);
int vi=0;
for(int i=0;i<boundary.Count;i+=keepEvery){ pl.AddVertexAt(vi++, boundary[i], 0,0,0); }
pl.Closed=true;
pl.Layer=A_HERO;
pl.LineWeight=LineWeight.ByLayer;
ms.AppendEntity(pl); tr.AddNewlyCreatedDBObject(pl,true);
Log($"drew A hero polyline verts={vi} on {A_HERO}");
tr.Commit();
}
Log("DONE. TRACT A full boundary on SS-HERO TRACT A @0.35 (bold on sheet A only, still frozen in sheet B VP).");
Result
Log
cleared old SS-HERO TRACT A entities: 1 explode produced 3 objects Hatch MText Polyline TRACT A boundary sample pts: 4 drew A hero polyline verts=4 on SS-HERO TRACT A DONE. TRACT A full boundary on SS-HERO TRACT A @0.35 (bold on sheet A only, still frozen in sheet B VP).
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.