← Inbox

C3D-0352 · Stake-out mode OFF: move STAKEOUT below No Display (group kept) [C3D-SOMODE-OFF] done

One script for both directions, run here with MODE=off. Creates the STAKEOUT group if it does not exist (so it works on a fresh drawing), rebuilds its IPF*/CP*/OTP* query and styles, then positions it in DrawOrder - top for on, immediately below 'No Display' for off. Verifies by reading the order back and checking the index. No other group, layout or point is touched.

Script file
C3D-0352.cs
Target
260714 - 285 Huckaby Rd R2.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
180s

C# payload

// STAKE-OUT MODE - one script, both directions.
//
//   MODE "on"  : STAKEOUT group goes to the TOP of DrawOrder  -> point numbers show
//   MODE "off" : STAKEOUT group goes just BELOW "No Display"  -> blanked, group kept
//
// The group is created if it does not exist, in EITHER mode, so this works on a fresh drawing.
// Nothing else is touched: no other group's styles, no layout, no point property.
const string MODE    = "off";                 // "on" or "off"
const string GRP     = "STAKEOUT";
const string BLANKER = "No Display";
const string PSTYLE  = "Iron Pin";
const string LSTYLE  = "Point#-Elevation-Description";
const string INCLUDE = "IPF*,CP*,OTP*";

var civ = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
Log("drawing: " + Db.Filename);
Log("mode: " + MODE);

// ---- resolve styles
ObjectId psId = ObjectId.Null, lsId = ObjectId.Null;
foreach (ObjectId sid in civ.Styles.PointStyles) {
    var st = (Autodesk.Civil.DatabaseServices.Styles.PointStyle)Tx.GetObject(sid, OpenMode.ForRead);
    if (st.Name == PSTYLE) { psId = sid; break; }
}
foreach (ObjectId sid in civ.Styles.LabelStyles.PointLabelStyles.LabelStyles) {
    var st = (Autodesk.Civil.DatabaseServices.Styles.LabelStyle)Tx.GetObject(sid, OpenMode.ForRead);
    if (st.Name == LSTYLE) { lsId = sid; break; }
}
if (psId.IsNull) { Log("point style \"" + PSTYLE + "\" missing - nothing done"); return; }
if (lsId.IsNull) { Log("label style \"" + LSTYLE + "\" missing - nothing done"); return; }

// ---- the group: create if absent, rebuild the query either way
ObjectId gid = ObjectId.Null;
foreach (ObjectId id in civ.PointGroups) {
    var pg = (Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(id, OpenMode.ForRead);
    if (pg.Name == GRP) { gid = id; break; }
}
if (gid.IsNull) { gid = civ.PointGroups.Add(GRP); Log("created group " + GRP); }
else Log("group " + GRP + " already present");

{
    var pg = (Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(gid, OpenMode.ForWrite);
    var q = new Autodesk.Civil.DatabaseServices.StandardPointGroupQuery();
    q.IncludeRawDescriptions = INCLUDE;
    pg.SetQuery(q);
    pg.PointStyleId = psId;
    pg.PointLabelStyleId = lsId;
    pg.IsPointStyleOverridden = true;
    pg.IsPointLabelStyleOverridden = true;
    pg.Update();
}

// ---- find the blanking group so "off" can hide behind it
ObjectId blankId = ObjectId.Null;
foreach (ObjectId id in civ.PointGroups) {
    var pg = (Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(id, OpenMode.ForRead);
    if (pg.Name == BLANKER) { blankId = id; break; }
}
if (MODE == "off" && blankId.IsNull) {
    Log("\"" + BLANKER + "\" group not found - cannot blank without it, nothing reordered");
    return;
}

// ---- reorder
{
    var rest = new List<ObjectId>();
    foreach (ObjectId id in civ.PointGroups.DrawOrder) if (id != gid) rest.Add(id);

    var newOrder = new ObjectIdCollection();
    if (MODE == "on") {
        newOrder.Add(gid);
        foreach (var id in rest) newOrder.Add(id);
    } else {
        foreach (var id in rest) {
            newOrder.Add(id);
            if (id == blankId) newOrder.Add(gid);   // immediately BELOW the blanker
        }
    }
    civ.PointGroups.DrawOrder = newOrder;
}

// ---- verify by reading the order back
{
    var pg = (Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(gid, OpenMode.ForRead);
    Log("");
    Log(string.Format("{0}: {1} points, query {2}", pg.Name, pg.GetPointNumbers().Length, pg.GetQuery().QueryString));
    int i = 0, iso = -1, ibl = -1;
    foreach (ObjectId id in civ.PointGroups.DrawOrder) {
        var p2 = (Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(id, OpenMode.ForRead);
        if (p2.Name == GRP)     iso = i;
        if (p2.Name == BLANKER) ibl = i;
        i++;
    }
    Log(string.Format("draw order: {0} at [{1}], {2} at [{3}]  (lower index = wins)", GRP, iso, BLANKER, ibl));
    bool ok = MODE == "on" ? (iso == 0) : (ibl >= 0 && iso == ibl + 1);
    Log(ok ? "position CORRECT for mode " + MODE : "*** position WRONG for mode " + MODE + " ***");
}
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd R2.dwg
Message
Executed C3D-0352 (0 entities touched).
Entities
Duration
405 ms
Civil 3D
25.0.0.0

Log

drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd R2.dwg
mode: off
group STAKEOUT already present

STAKEOUT: 13 points, query (RawDescription='IPF*' OR RawDescription='CP*' OR RawDescription='OTP*')
draw order: STAKEOUT at [9], No Display at [8]  (lower index = wins)
position CORRECT for mode off

Notes

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

No notes yet.