← Inbox

C3D-0351 · Stake-out setup: STAKEOUT point group (IPF/CP/OTP) promoted to top + PNEZD file [C3D-STAKEOUT] done

Creates or rebuilds a point group named STAKEOUT whose query is IncludeRawDescriptions 'IPF*,CP*,OTP*', assigns Iron Pin + Point#-Elevation-Description so point numbers are visible, and promotes it to the top of DrawOrder so its display is not overridden by _All Points or No Display. Then writes those points as PNEZD comma (descriptions scrubbed of quotes and commas) and verifies the group count equals the file line count. No existing point group, layout, or point property is modified - turning stake-out off later is just deleting this one group.

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

C# payload

// STAKE-OUT SETUP
//   1. build/rebuild a STAKEOUT point group from a raw-description wildcard query
//   2. give it Iron Pin + Point#-Elevation-Description and promote it to the TOP of DrawOrder
//      so its display wins over _All Points / No Display
//   3. write the matching points as PNEZD comma
//   4. verify group count == file lines
//
// Nothing else is touched: no existing group's styles, no layout, no point's own properties.
// Turning stake-out OFF is one line elsewhere - delete the STAKEOUT group; every plat group is
// exactly as it was.
const string GRP     = "STAKEOUT";
const string PSTYLE  = "Iron Pin";
const string LSTYLE  = "Point#-Elevation-Description";
const string INCLUDE = "IPF*,CP*,OTP*";      // raw-description wildcards, comma separated

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

// ---- styles, by exact name
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; }
Log("styles resolved: \"" + PSTYLE + "\" + \"" + LSTYLE + "\"");

// ---- group: reuse if present, never make STAKEOUT (2)
ObjectId gid;
bool existed = civ.PointGroups.Contains(GRP);
if (existed) {
    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; }
    }
    Log("group " + GRP + " exists - rebuilding in place");
} else {
    gid = civ.PointGroups.Add(GRP);
    Log("created group " + GRP);
}

{
    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();
}

// ---- promote to the top of DrawOrder, or the display is silently overridden
{
    var order = civ.PointGroups.DrawOrder;
    var ids = new List<ObjectId>();
    foreach (ObjectId id in order) if (id != gid) ids.Add(id);
    var reordered = new ObjectIdCollection();
    reordered.Add(gid);
    foreach (var id in ids) reordered.Add(id);
    civ.PointGroups.DrawOrder = reordered;
}

// ---- read back what the group actually is
uint[] nums;
{
    var pg = (Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(gid, OpenMode.ForRead);
    nums = pg.GetPointNumbers();
    var q = pg.GetQuery();
    var ps = (Autodesk.Civil.DatabaseServices.Styles.PointStyle)Tx.GetObject(pg.PointStyleId, OpenMode.ForRead);
    var ls = (Autodesk.Civil.DatabaseServices.Styles.LabelStyle)Tx.GetObject(pg.PointLabelStyleId, OpenMode.ForRead);
    Log("");
    Log("GROUP " + pg.Name + " (verified)");
    Log("   query   : " + q.QueryString);
    Log("   points  : " + nums.Length);
    Log("   style   : \"" + ps.Name + "\"   label: \"" + ls.Name + "\"");
}
{
    int i = 0;
    foreach (ObjectId id in civ.PointGroups.DrawOrder) {
        var pg = (Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(id, OpenMode.ForRead);
        if (i < 3) Log(string.Format("   draworder[{0}] {1}", i, pg.Name));
        i++;
    }
}

// ---- the file. E:\DATA is not on this machine, so it goes beside the drawing and we SAY so.
string EDIR = "E:" + ((char)92) + "DATA";
string dir  = System.IO.Directory.Exists(EDIR) ? EDIR : System.IO.Path.GetDirectoryName(Db.Filename);
if (!System.IO.Directory.Exists(EDIR)) Log("");
if (!System.IO.Directory.Exists(EDIR)) Log(EDIR + " not present - writing beside the drawing instead");
string outPath = System.IO.Path.Combine(dir,
    System.IO.Path.GetFileNameWithoutExtension(Db.Filename) + " - STAKEOUT.txt");

var want = new HashSet<uint>(nums);
var rows = new List<KeyValuePair<uint,string>>();
foreach (ObjectId id in civ.CogoPoints) {
    var p = (Autodesk.Civil.DatabaseServices.CogoPoint)Tx.GetObject(id, OpenMode.ForRead);
    if (!want.Contains((uint)p.PointNumber)) continue;
    // scrub the description: data collectors choke on quotes and commas
    var sb = new System.Text.StringBuilder();
    foreach (char c in (p.RawDescription ?? "")) sb.Append(char.IsLetterOrDigit(c) || c == ' ' ? c : ' ');
    string d = sb.ToString().Trim();
    while (d.Contains("  ")) d = d.Replace("  ", " ");
    rows.Add(new KeyValuePair<uint,string>((uint)p.PointNumber,
        string.Format("{0},{1:F4},{2:F4},{3:F4},{4}", p.PointNumber, p.Northing, p.Easting, p.Elevation, d)));
}
rows.Sort((a,b) => a.Key.CompareTo(b.Key));
var text = new System.Text.StringBuilder();
foreach (var r in rows) text.Append(r.Value).Append("\r\n");
System.IO.File.WriteAllText(outPath, text.ToString(), new System.Text.UTF8Encoding(false));

var lines = System.IO.File.ReadAllLines(outPath);
Log("");
Log("WROTE " + outPath);
foreach (var l in lines) Log("    " + l);

Log("");
Log(string.Format("VERIFY: group={0}  file lines={1}  {2}",
    nums.Length, lines.Length, nums.Length == lines.Length ? "MATCH" : "*** MISMATCH ***"));
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-0351 (0 entities touched).
Entities
Duration
457 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
styles resolved: "Iron Pin" + "Point#-Elevation-Description"
created group STAKEOUT

GROUP STAKEOUT (verified)
   query   : (RawDescription='IPF*' OR RawDescription='CP*' OR RawDescription='OTP*')
   points  : 15
   style   : "Iron Pin"   label: "Point#-Elevation-Description"
   draworder[0] STAKEOUT
   draworder[1] PP
   draworder[2] POB

E:\DATA not present - writing beside the drawing instead

WROTE C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd R2 - STAKEOUT.txt
    364,1207312.9316,2206379.5725,854.2948,IPF
    406,1207293.5077,2203443.1704,823.3011,OTP
    500,1207293.3588,2203443.1687,823.2429,IPF
    510,1206809.8163,2203438.7211,837.3701,IPF 4 POST
    520,1206709.9971,2203439.2944,854.2900,IPF
    521,1206719.6631,2205253.5086,854.2900,IPF
    522,1206798.9689,2205255.8347,854.2900,IPF
    523,1206809.1899,2206344.7867,854.2900,IPF
    524,1206809.3083,2206364.0576,854.2900,CP
    525,1206717.3657,2204844.8382,854.2900,IPF
    526,1206967.3546,2204842.4917,854.2900,IPF
    527,1206969.7050,2205260.7851,854.2900,IPF
    528,1206948.9038,2205260.1811,854.2900,IPF
    529,1206959.1267,2206349.1408,854.2900,CP
    531,1206959.1830,2206355.1445,854.2900,IPF

VERIFY: group=15  file lines=15  MATCH

Notes

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

No notes yet.