← Inbox

C3D-BLDGRECT · Draw building as a rectangle done

Fits an orthogonal 88.8x32.7ft rectangle (rot 52.2deg) to the 10 BLDG points instead of threading a path through them. Ratio 20.3, area 2905sf. Six points land within 0.12ft of it.

Script file
C3D-BLDGRECT.cs
Target
active document · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// Building: fit an ORTHOGONAL RECTANGLE to the 10 *BLDG* points instead of threading a path
// through them. 88.8 x 32.7 ft, rotated 52.2 deg, area 2905 sf, perimeter 243.1 ft,
// perimeter^2/area = 20.3 (square is 16; a building is 16-25).
// Point fit: 610/613/639/664 dead on (0.00ft), 645/699/701 within 0.12ft, 620/640/646 ~3ft
// inside (wall jogs). Prior path-through-points attempts gave ratio 82 (sliver) and 21 but
// with 5 parallel edges - neither looked like a building.
// Host owns Tx/ModelSpace - no using/Commit here.
int erased = 0;
foreach (ObjectId id in ModelSpace)
{
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null || e.Layer != "SS-V-BLDG-OTLN") continue;
    var p = e as Polyline;
    if (p == null || p.NumberOfVertices != 10) continue;
    var w = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
    w.Erase();
    erased++;
}
Log($"Erased {erased} prior outline(s).");

var pl = new Polyline();
    pl.AddVertexAt(0, new Point2d(2428031.736043926, 1064432.7972668759), 0, 0, 0);
    pl.AddVertexAt(1, new Point2d(2428086.185480262, 1064502.9930572256), 0, 0, 0);
    pl.AddVertexAt(2, new Point2d(2428060.350105576, 1064523.0330280298), 0, 0, 0);
    pl.AddVertexAt(3, new Point2d(2428005.9006692395, 1064452.83723768), 0, 0, 0);
pl.Closed = true;
pl.Elevation = 419.15;
pl.Layer = "SS-V-BLDG-OTLN";
ModelSpace.AppendEntity(pl);
Tx.AddNewlyCreatedDBObject(pl, true);
Log($"Drew building rectangle: {pl.NumberOfVertices} verts, closed={pl.Closed}, len={pl.Length:F1}.");

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260709 - 1512 Bass Rd, Macon, GA 31210, USA\260709 - 1512 Bass Rd.dwg
Message
Executed C3D-BLDGRECT (0 entities touched).
Entities
Duration
341 ms
Civil 3D
25.0.0.0

Log

Erased 1 prior outline(s).
Drew building rectangle: 4 verts, closed=True, len=243.1.

Notes

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

No notes yet.