← Inbox

C3D-260619-MOVEPROP · Move C-PROP-LINE contents to SS-C-PROP-LINE error

Creates SS-C-PROP-LINE and moves everything off C-PROP-LINE onto it, so C-PROP-LINE can be turned off without hiding the HERO/TRACT ParcelSegmentLabels (labels follow their parents visibility). Nothing exploded or erased; verifies C-PROP-LINE is empty and label count unchanged.

Script file
C3D-260619-MOVEPROP.cs
Target
260619 · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// Move everything on C-PROP-LINE to a new layer SS-C-PROP-LINE so C-PROP-LINE can be turned
// off without hiding the HERO/TRACT annotation.
//
// WHY: the 11 ParcelSegmentLabels on SS-HERO TRACT A/B ANNO have parents (ParcelSegments) that
// live on C-PROP-LINE. A Civil 3D label follows its PARENT's visibility, so turning C-PROP-LINE
// off hid the labels regardless of their own layer. Moving the parents onto their own layer
// leaves C-PROP-LINE empty - turning it off then hides nothing.
//
// Labels stay real, live Civil 3D labels (nothing is exploded, nothing is erased).
// Verifies afterwards that C-PROP-LINE is empty and the label count is unchanged.
// Host owns Tx; host regens after commit.
const string OLD = "C-PROP-LINE", NEW = "SS-C-PROP-LINE";

var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForWrite);

// count the HERO/TRACT labels before, so we can prove none were lost
bool IsHero(string s) { var u = s.ToUpper(); return u.Contains("HERO") || u.Contains("TRACT"); }
int labelsBefore = 0;
foreach (ObjectId id in ms)
{
    var l = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Label;
    if (l != null && IsHero(l.Layer)) labelsBefore++;
}
Log("HERO/TRACT labels before: " + labelsBefore);

// source layer colour, so the new layer looks the same
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
short colour = 7;
if (lt.Has(OLD))
{
    var src = (LayerTableRecord)Tx.GetObject(lt[OLD], OpenMode.ForRead);
    colour = src.Color.ColorIndex;
}
EnsureLayer(NEW, colour);
Log("layer '" + NEW + "' ready (colour " + colour + ")");

// move every model-space entity off OLD
var toMove = new List<ObjectId>();
foreach (ObjectId id in ms)
{
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e != null && e.Layer == OLD) toMove.Add(id);
}
Log("entities on '" + OLD + "': " + toMove.Count);

int moved = 0;
foreach (var id in toMove)
{
    var e = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
    var kind = e.GetType().Name;
    e.Layer = NEW;
    moved++;
    Log("  moved " + kind + " h=" + e.Handle + " -> '" + NEW + "'");
}

// verify
int leftOnOld = 0, labelsAfter = 0;
foreach (ObjectId id in ms)
{
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e == null) continue;
    if (e.Layer == OLD) leftOnOld++;
    var l = e as Autodesk.Civil.DatabaseServices.Label;
    if (l != null && IsHero(l.Layer)) labelsAfter++;
}
Log("moved " + moved + "; '" + OLD + "' now holds " + leftOnOld + " entities" +
    (leftOnOld == 0 ? " (empty - safe to turn off)" : " (STILL OCCUPIED)"));
Log("HERO/TRACT labels after: " + labelsAfter +
    (labelsAfter == labelsBefore ? " (unchanged - verified)" : " (CHANGED! " + labelsBefore + " -> " + labelsAfter + ")"));

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260619 - 3625 Stonewall Tell Rd, Atlanta, GA 30349, USA\260619 - 3625 Stonewall Tell Rd ROTATE.dwg
Message
eOnLockedLayer
Entities
Duration
616 ms
Civil 3D
25.0.0.0

Log

HERO/TRACT labels before: 11
layer 'SS-C-PROP-LINE' ready (colour 230)
entities on 'C-PROP-LINE': 3

Notes

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

No notes yet.