← Inbox

C3D-LBLOWNER · Group ParcelSegmentLabels by owning parcel (read-only) done

Resolve each ParcelSegmentLabel to TRACT A or B via FeatureId — authoritative bearing->tract mapping.

Script file
C3D-LBLOWNER.cs
Target
active document · model space
Author
claude
Approved
yes · claude (read-only)
Timeout
60s

C# payload

// READ-ONLY: group the bearing labels by the PARCEL they belong to (authoritative, not spatial).
// For each Parcel (TRACT A / TRACT B): list its ParcelSegmentLabel ids via the parcel's label API if
// available; else report each ParcelSegmentLabel's FeatureId owner. Also dump each parcel's segment
// count + area so we confirm A's geometry is readable.
using System;
using System.Linq;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;

var db = Db;
using (var tr = db.TransactionManager.StartTransaction())
{
    var cdoc = CivilDocument.GetCivilDocument(db);
    // map parcel ObjectId -> name
    var parcelName = new Dictionary<ObjectId,string>();
    foreach (ObjectId sid in cdoc.GetSiteIds())
    {
        var site=(Site)tr.GetObject(sid,OpenMode.ForRead);
        foreach (ObjectId pid in site.GetParcelIds())
        {
            var p=(Parcel)tr.GetObject(pid,OpenMode.ForRead);
            parcelName[pid]=p.Name;
            Log($"PARCEL '{p.Name}' id={pid} layer='{p.Layer}' area={p.Area/43560.0:0.000}ac");
        }
    }

    // walk ParcelSegmentLabels, resolve owning parcel via FeatureId
    var ms=(BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),OpenMode.ForRead);
    var byParcel = new SortedDictionary<string,List<string>>();
    int psl=0;
    foreach (ObjectId id in ms)
    {
        var e=tr.GetObject(id,OpenMode.ForRead);
        if (e is ParcelSegmentLabel ps)
        {
            psl++;
            string owner="?";
            try {
                var fid = ps.FeatureId;
                // FeatureId points at the parcel (or its segment's parent). Resolve to a parcel name.
                if (parcelName.TryGetValue(fid, out var nm)) owner=nm;
                else {
                    // maybe FeatureId is a parcel; open and read name
                    var fo = tr.GetObject(fid, OpenMode.ForRead);
                    if (fo is Parcel pp) owner=pp.Name;
                    else owner=fo.GetType().Name;
                }
            } catch (System.Exception ex) { owner=$"(err {ex.Message})"; }
            string key=owner;
            if(!byParcel.TryGetValue(key,out var lst)){lst=new List<string>();byParcel[key]=lst;}
            lst.Add($"{ps.Handle}@{ps.Layer}");
        }
    }
    Log($"ParcelSegmentLabels total={psl}");
    foreach (var kv in byParcel){ Log($"OWNER '{kv.Key}' ({kv.Value.Count}): {string.Join(", ", kv.Value.Take(30))}"); }
    tr.Commit();
}

Result

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

Log

PARCEL 'TRACT "B"' id=(1744407580400) layer='C-PROP' area=3.314ac
PARCEL 'TRACT "A"' id=(1744407580192) layer='SS-BOUNDARY TRACT A' area=0.994ac
ParcelSegmentLabels total=12
OWNER 'ParcelSegment' (12): 20CFD@C-PROP-LINE-TEXT, 20CFE@C-PROP-LINE-TEXT, 20CFF@C-PROP-LINE-TEXT, 2103E@C-PROP-LINE-TEXT, 21078@C-PROP-LINE-TEXT, 21079@C-PROP-LINE-TEXT, 2107A@C-PROP-LINE-TEXT, 2107B@C-PROP-LINE-TEXT, 2107C@C-PROP-LINE-TEXT, 2107D@C-PROP-LINE-TEXT, 2107E@C-PROP-LINE-TEXT, 2107F@C-PROP-LINE-TEXT

Notes

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

No notes yet.