← Inbox

C3D-260619-MOVEPROP2 · Move C-PROP-LINE contents to SS-C-PROP-LINE (unlock first) done

Unlocks C-PROP-LINE, moves its 3 entities to SS-C-PROP-LINE, re-locks it. Lets C-PROP-LINE be turned off without hiding the HERO/TRACT ParcelSegmentLabels. Nothing exploded or erased; verifies the layer is empty and label count unchanged.

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

C# payload

// Move everything on C-PROP-LINE to 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) on
// C-PROP-LINE. A Civil 3D label follows its PARENT's visibility, so turning C-PROP-LINE off hid
// them regardless of their own layer. With the parents moved, C-PROP-LINE is empty and turning
// it off hides nothing. Labels stay live - nothing is exploded or erased.
//
// C-PROP-LINE is LOCKED (first attempt failed with eOnLockedLayer), so this unlocks it, moves,
// then restores the original lock state.
// 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);
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);

var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
if (!lt.Has(OLD)) { Log("'" + OLD + "' not found."); return; }

var oldLtr = (LayerTableRecord)Tx.GetObject(lt[OLD], OpenMode.ForWrite);
bool wasLocked = oldLtr.IsLocked;
short colour = oldLtr.Color.ColorIndex;
Log("'" + OLD + "' locked=" + wasLocked + " colour=" + colour);
if (wasLocked) { oldLtr.IsLocked = false; Log("  unlocked for the move"); }

EnsureLayer(NEW, colour);

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 + "'");
}

if (wasLocked) { oldLtr.IsLocked = true; Log("  '" + OLD + "' re-locked"); }

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 +
    (leftOnOld == 0 ? " (empty - safe to turn off)" : " (STILL OCCUPIED)"));
Log("HERO/TRACT labels after: " + labelsAfter +
    (labelsAfter == labelsBefore ? " (unchanged - verified)" : " (CHANGED! " + labelsBefore + " -> " + labelsAfter + ")"));

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260619 - 3625 Stonewall Tell Rd, Atlanta, GA 30349, USA\260619 - 3625 Stonewall Tell Rd ROTATE.dwg
Message
Executed C3D-260619-MOVEPROP2 (0 entities touched).
Entities
Duration
408 ms
Civil 3D
25.0.0.0

Log

HERO/TRACT labels before: 11
'C-PROP-LINE' locked=False colour=230
entities on 'C-PROP-LINE': 3
  moved ParcelSegment h=101C9 -> 'SS-C-PROP-LINE'
  moved ParcelSegment h=20CFA -> 'SS-C-PROP-LINE'
  moved ParcelSegment h=21076 -> 'SS-C-PROP-LINE'
moved 3; 'C-PROP-LINE' now holds 0 (empty - safe to turn off)
HERO/TRACT labels after: 11 (unchanged - verified)

Notes

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

No notes yet.