← Inbox

C3D-MHOLBLOCKS · Convert manhole symbols to block inserts (HCWA Type=Insert) done

Define SSMH_OUTFALL + SSMH_BOLTED blocks (r=5ft), erase the 15 raw circle/polyline entities, insert blocks at the 14 SSMH points via InsertBlock. Matches HCWA table Type=Insert for SEWER_MANHOLE/SEWER_MANHOLE_EXISTING.

Script file
C3D-MHOLBLOCKS.cs
Target
SS_Outfall_260612_SHEET.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// Convert manhole symbols to true block INSERTS (HCWA table type = Insert), per the spec.
// 1) Define two block definitions: SSMH_OUTFALL (open circle, blue) and SSMH_BOLTED (filled circle,
//    gray, via a donut polyline — no Hatch per house rule).
// 2) Erase the 15 raw Circle/Polyline entities on SEWER_MANHOLE / SEWER_MANHOLE_EXISTING.
// 3) Insert SSMH_OUTFALL at points 7000-7012, SSMH_BOLTED at point 7013, using InsertBlock().
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;

const double R = 5.0; // symbol radius, feet (matches the last confirmed size)
const string BLK_OUTFALL = "SSMH_OUTFALL";
const string BLK_BOLTED  = "SSMH_BOLTED";

EnsureLayer("SEWER_MANHOLE", 5);
EnsureLayer("SEWER_MANHOLE_EXISTING", 8);

var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForWrite);

ObjectId DefineBlock(string name, Action<BlockTableRecord> draw)
{
    if (bt.Has(name)) return bt[name];
    var btr = new BlockTableRecord { Name = name, Origin = Point3d.Origin };
    bt.Add(btr);
    Tx.AddNewlyCreatedDBObject(btr, true);
    draw(btr);
    return btr.ObjectId;
}

// SSMH_OUTFALL: open circle, blue, centered on origin so InsertBlock's position = the point
DefineBlock(BLK_OUTFALL, btr =>
{
    var c = new Circle(Point3d.Origin, Vector3d.ZAxis, R);
    c.Color = Color.FromColorIndex(ColorMethod.ByAci, 5);
    btr.AppendEntity(c);
    Tx.AddNewlyCreatedDBObject(c, true);
});

// SSMH_BOLTED: filled circle via donut polyline (no Hatch), gray
DefineBlock(BLK_BOLTED, btr =>
{
    var c = new Circle(Point3d.Origin, Vector3d.ZAxis, R);
    c.Color = Color.FromColorIndex(ColorMethod.ByAci, 8);
    btr.AppendEntity(c);
    Tx.AddNewlyCreatedDBObject(c, true);

    var donut = new Polyline();
    donut.AddVertexAt(0, new Point2d(-R, 0), 1.0, R, R);
    donut.AddVertexAt(1, new Point2d(R, 0), 1.0, R, R);
    donut.Closed = true;
    donut.Color = Color.FromColorIndex(ColorMethod.ByAci, 8);
    btr.AppendEntity(donut);
    Tx.AddNewlyCreatedDBObject(donut, true);
});

Log($"defined blocks '{BLK_OUTFALL}' and '{BLK_BOLTED}'.");

// erase the raw circle/polyline symbols on the manhole layers
int erased = 0;
foreach (ObjectId id in ModelSpace)
{
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null) continue;
    if (!string.Equals(e.Layer, "SEWER_MANHOLE", StringComparison.OrdinalIgnoreCase)
     && !string.Equals(e.Layer, "SEWER_MANHOLE_EXISTING", StringComparison.OrdinalIgnoreCase)) continue;
    if (!(e is Circle) && !(e is Polyline)) continue;
    var w = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
    w.Erase();
    erased++;
}
Log($"erased raw manhole entities: {erased}");

// insert blocks at each point
int outfall = 0, bolted = 0;
var cdoc = CivilDocument.GetCivilDocument(Db);
foreach (ObjectId id in cdoc.CogoPoints)
{
    var cp = Tx.GetObject(id, OpenMode.ForRead) as CogoPoint;
    if (cp == null) continue;
    int n = (int)cp.PointNumber;
    if (n < 7000 || n > 7013) continue;

    var pos = new Point3d(cp.Easting, cp.Northing, 0);
    if (n == 7013)
    {
        InsertBlock(BLK_BOLTED, pos, 1.0, 0.0, "SEWER_MANHOLE_EXISTING");
        bolted++;
    }
    else
    {
        InsertBlock(BLK_OUTFALL, pos, 1.0, 0.0, "SEWER_MANHOLE");
        outfall++;
    }
}
Log($"inserted blocks: outfall={outfall}, bolted={bolted}");
Log("DONE. Manhole symbols are now true block INSERTS per HCWA table Type=Insert.");

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\SS_Outfall_260612_SHEET.dwg
Message
Executed C3D-MHOLBLOCKS (14 entities touched).
Entities
18BC, 18BD, 18BE, 18BF, 18C0, 18C1, 18C2, 18C3, 18C4, 18C5, 18C6, 18C7, 18C8, 18C9
Duration
505 ms
Civil 3D
25.0.0.0

Log

defined blocks 'SSMH_OUTFALL' and 'SSMH_BOLTED'.
erased raw manhole entities: 7
inserted blocks: outfall=13, bolted=1
DONE. Manhole symbols are now true block INSERTS per HCWA table Type=Insert.

Notes

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

No notes yet.