← Inbox

C3D-260612-MOVEPTS · Move WATER_LINE_EXISTING_TEXT points to SS-5000-PTS done

Creates SS-5000-PTS and moves ONLY the CogoPoints currently on WATER_LINE_EXISTING_TEXT onto it. All other entities on that layer are left alone. Verifies the counts on both layers afterwards.

Script file
C3D-260612-MOVEPTS.cs
Target
260612 · model space
Author
claude
Approved
yes · reviewer
Timeout
180s

C# payload

// Move ONLY the CogoPoints that are on WATER_LINE_EXISTING_TEXT to a new layer SS-5000-PTS.
// Everything else on WATER_LINE_EXISTING_TEXT (text, linework, whatever) STAYS - this touches
// CogoPoints and nothing else.
// Unlocks the source layer if needed and restores its lock state (eOnLockedLayer bit us before).
// Verifies afterwards: how many points remain on the source layer, how many are on the new one.
// Host owns Tx; host regens after commit.
const string SRC = "WATER_LINE_EXISTING_TEXT", DST = "SS-5000-PTS";

var cd = CivilDoc;
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);

short colour = 7;
bool wasLocked = false;
LayerTableRecord srcLtr = null;
if (lt.Has(SRC)) {
    srcLtr = (LayerTableRecord)Tx.GetObject(lt[SRC], OpenMode.ForWrite);
    colour = srcLtr.Color.ColorIndex;
    wasLocked = srcLtr.IsLocked;
    if (wasLocked) { srcLtr.IsLocked = false; Log("unlocked '" + SRC + "' for the move"); }
} else {
    Log("'" + SRC + "' not found"); return;
}

EnsureLayer(DST, colour);
Log("layer '" + DST + "' ready (colour " + colour + ")");

var toMove = new List<ObjectId>();
foreach (ObjectId id in cd.CogoPoints) {
    var cp = Tx.GetObject(id, OpenMode.ForRead) as CogoPoint;
    if (cp != null && cp.Layer == SRC) toMove.Add(id);
}
Log("CogoPoints on '" + SRC + "': " + toMove.Count);

int moved = 0;
foreach (var id in toMove) {
    var cp = (CogoPoint)Tx.GetObject(id, OpenMode.ForWrite);
    cp.Layer = DST;
    moved++;
}
if (wasLocked) { srcLtr.IsLocked = true; Log("'" + SRC + "' re-locked"); }

int leftSrc = 0, onDst = 0;
foreach (ObjectId id in cd.CogoPoints) {
    var cp = Tx.GetObject(id, OpenMode.ForRead) as CogoPoint;
    if (cp == null) continue;
    if (cp.Layer == SRC) leftSrc++;
    if (cp.Layer == DST) onDst++;
}

int otherOnSrc = 0;
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
foreach (ObjectId id in ms) {
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e != null && e.Layer == SRC && !(e is CogoPoint)) otherOnSrc++;
}

Log("moved " + moved + " point(s) -> '" + DST + "'");
Log("CogoPoints now: " + onDst + " on '" + DST + "', " + leftSrc + " still on '" + SRC + "' (verified)");
Log("non-point entities left on '" + SRC + "': " + otherOnSrc + " (untouched)");

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\CSTORE WATER ABS-260612_SHEET.dwg
Message
Executed C3D-260612-MOVEPTS (0 entities touched).
Entities
Duration
642 ms
Civil 3D
25.0.0.0

Log

layer 'SS-5000-PTS' ready (colour 5)
CogoPoints on 'WATER_LINE_EXISTING_TEXT': 443
moved 443 point(s) -> 'SS-5000-PTS'
CogoPoints now: 443 on 'SS-5000-PTS', 0 still on 'WATER_LINE_EXISTING_TEXT' (verified)
non-point entities left on 'WATER_LINE_EXISTING_TEXT': 0 (untouched)

Notes

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

No notes yet.