← Inbox

C3D-CURBOFF · Offset curb 0.5 and 2.0 toward road done

Offsets each curb Polyline on SS-V-ROAD-CURB by 0.5ft (top face) and 2.0ft (flowline) toward the road. Direction chosen per run by testing both sides and keeping the one farther from the building centroid.

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

C# payload

// STEP 2: curb-and-gutter offsets. TBC (top back of curb) is the surveyed line; offset it
// TOWARD THE ROAD by 0.5' (top face of curb) and 2.0' (flowline / gutter lip).
// Direction per run: offset both ways, keep the side whose midpoint lands FARTHER from the
// building footprint centroid (the road side). Runs are drawn in arbitrary directions so a
// fixed left/right rule does not work.
// Host owns Tx/ModelSpace - no using/Commit here.
const string LAYER = "SS-V-ROAD-CURB";
const double MINLEN = 3.0, MAXLEN = 500.0;

// building centroid = the "away from road" reference
double bx = 0, by = 0; int bn = 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) continue;
    for (int i = 0; i < p.NumberOfVertices; i++) { var v = p.GetPoint2dAt(i); bx += v.X; by += v.Y; bn++; }
}
if (bn == 0) { Log("No building outline found - cannot determine road side."); return; }
bx /= bn; by /= bn;
Log($"Building centroid ({bx:F2},{by:F2}) from {bn} verts.");

var srcs = new List<ObjectId>();
foreach (ObjectId id in ModelSpace)
{
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null || e.Layer != LAYER) continue;
    var p = e as Polyline;
    if (p == null) continue;
    if (p.Length < MINLEN || p.Length > MAXLEN) continue;
    srcs.Add(id);
}
Log($"{srcs.Count} curb Polylines to offset.");

double DistFromBldg(Autodesk.AutoCAD.DatabaseServices.Entity e)
{
    var p = e as Polyline;
    if (p == null || p.NumberOfVertices == 0) return -1;
    double mx = 0, my = 0;
    for (int i = 0; i < p.NumberOfVertices; i++) { var v = p.GetPoint2dAt(i); mx += v.X; my += v.Y; }
    mx /= p.NumberOfVertices; my /= p.NumberOfVertices;
    return System.Math.Sqrt((mx-bx)*(mx-bx) + (my-by)*(my-by));
}

int made = 0, failed = 0;
foreach (var id in srcs)
{
    var pl = (Polyline)Tx.GetObject(id, OpenMode.ForRead);
    int sign = 0;
    try
    {
        var pos = pl.GetOffsetCurves(0.5);
        var neg = pl.GetOffsetCurves(-0.5);
        double dp = pos.Count > 0 ? DistFromBldg((Autodesk.AutoCAD.DatabaseServices.Entity)pos[0]) : -1;
        double dn = neg.Count > 0 ? DistFromBldg((Autodesk.AutoCAD.DatabaseServices.Entity)neg[0]) : -1;
        if (dp < 0 && dn < 0) { failed++; continue; }
        sign = (dp >= dn) ? 1 : -1;
    }
    catch { failed++; continue; }

    foreach (double d in new double[] { 0.5, 2.0 })
    {
        try
        {
            var curves = pl.GetOffsetCurves(sign * d);
            foreach (Autodesk.AutoCAD.DatabaseServices.Entity oe in curves)
            {
                oe.Layer = LAYER;
                ModelSpace.AppendEntity(oe);
                Tx.AddNewlyCreatedDBObject(oe, true);
                made++;
            }
        }
        catch { failed++; }
    }
}
Log($"Created {made} offset curves (0.5' face + 2.0' flowline) from {srcs.Count} runs. {failed} failures.");

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-CURBOFF (0 entities touched).
Entities
Duration
475 ms
Civil 3D
25.0.0.0

Log

Building centroid (2428047.81,1064467.84) from 17 verts.
62 curb Polylines to offset.
Created 125 offset curves (0.5' face + 2.0' flowline) from 62 runs. 0 failures.

Notes

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

No notes yet.