← Inbox

C3D-0304 · 260610 Tara Blvd: TXT2MTXT the WHOLE drawing + all text to Arial done

C3D-0303 only covered the store bounding box. This converts every DBText in the entire drawing - model space, all layouts, all block definitions - to MText preserving position/height/rotation/layer/colour, and puts all text on GF_050 (real arial.ttf). Attribute definitions are RESTYLED but not converted (converting breaks title block wiring). The BLOCK_STAMP layers are skipped entirely - the surveyor seal is dozens of tiny rotated glyphs forming the circular artwork. Verifies across the whole drawing that no DBText remains and nothing is off the Arial style.

Script file
C3D-0304.cs
Target
260610 - 6736 Tara Blvd R2.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// Convert EVERY DBText in the drawing to MText and put ALL text on real Arial (GF_050 = arial.ttf).
// C3D-0303 only did the store bounding box; this does the whole drawing - model space, every
// layout, and every block definition.
//
// SKIPPED deliberately:
//   - AttributeDefinition / AttributeReference: converting those breaks the title block's
//     attribute wiring. They are RESTYLED to Arial but stay attributes.
//   - Dimension text, table text, Civil labels: owned by their parent object, not free text.
//   - The BLOCK_STAMP layer: the surveyor's seal is dozens of tiny rotated glyphs forming the
//     circular stamp artwork. Converting or restyling those would wreck it.
const string FONT = "GF_050";

var tst = (TextStyleTable)Tx.GetObject(Db.TextStyleTableId, OpenMode.ForRead);
if (!tst.Has(FONT)) { Log("style " + FONT + " missing"); return; }
ObjectId styleId = tst[FONT];
{
    var ts = (TextStyleTableRecord)Tx.GetObject(styleId, OpenMode.ForRead);
    string tt = ""; try { tt = ts.Font.TypeFace; } catch { }
    Log("font: " + ts.Name + " -> " + ts.FileName + " (\"" + tt + "\")");
}

var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);

// collect per-space first: never convert while iterating the same BTR
var spaces = new List<ObjectId>();
foreach (ObjectId id in bt) spaces.Add(id);

int conv = 0, restyled = 0, skippedStamp = 0, attrs = 0;
var perSpace = new Dictionary<string,int>();

foreach (ObjectId btrId in spaces) {
    var rec0 = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
    string where = rec0.Name;
    if (rec0.IsLayout) { var l = (Layout)Tx.GetObject(rec0.LayoutId, OpenMode.ForRead); where = "LAYOUT " + l.LayoutName; }

    var todo = new List<ObjectId>();
    foreach (ObjectId id in rec0) {
        var ent = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (ent == null || ent.IsErased) continue;
        if (ent is AttributeDefinition) { todo.Add(id); continue; }
        if (ent is DBText || ent is MText) todo.Add(id);
    }
    if (todo.Count == 0) continue;

    var rec = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForWrite);
    int here = 0;

    foreach (ObjectId id in todo) {
        var ent = Tx.GetObject(id, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (ent == null || ent.IsErased) continue;

        // the seal artwork must not be touched
        if (ent.Layer.IndexOf("STAMP", StringComparison.OrdinalIgnoreCase) >= 0) { skippedStamp++; continue; }

        // attributes: restyle only, never convert
        var ad = ent as AttributeDefinition;
        if (ad != null) { ad.TextStyleId = styleId; attrs++; here++; continue; }

        var dt = ent as DBText;
        if (dt != null) {
            var nm = new MText();
            nm.SetDatabaseDefaults();
            nm.TextStyleId = styleId;
            nm.TextHeight = dt.Height;
            nm.Location = dt.Position;
            nm.Rotation = dt.Rotation;
            nm.Attachment = AttachmentPoint.BottomLeft;
            nm.Layer = dt.Layer;
            nm.Color = dt.Color;
            nm.Contents = dt.TextString;
            rec.AppendEntity(nm);
            Tx.AddNewlyCreatedDBObject(nm, true);
            dt.Erase();
            conv++; here++;
            continue;
        }

        var mt = ent as MText;
        if (mt != null) { mt.TextStyleId = styleId; restyled++; here++; }
    }

    if (here > 0) perSpace[where] = here;
}

Log("");
foreach (var kv in perSpace) Log(string.Format("  {0,-34} {1} text entities", kv.Key, kv.Value));
Log("");
Log(string.Format("converted {0} DBText -> MText, restyled {1} MText, restyled {2} attribute defs, skipped {3} on STAMP layers",
    conv, restyled, attrs, skippedStamp));

// ---- verify the whole drawing
int leftDb = 0, wrongStyle = 0, totalTxt = 0;
foreach (ObjectId btrId in bt) {
    var rec = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
    foreach (ObjectId id in rec) {
        var ent = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (ent == null || ent.IsErased) continue;
        if (ent.Layer.IndexOf("STAMP", StringComparison.OrdinalIgnoreCase) >= 0) continue;
        var d = ent as DBText; var m = ent as MText;
        if (d == null && m == null) continue;
        totalTxt++;
        if (d != null) leftDb++;
        ObjectId sid = d != null ? d.TextStyleId : m.TextStyleId;
        if (sid != styleId) wrongStyle++;
    }
}
Log(string.Format("VERIFY (whole drawing, excluding STAMP): {0} text entities, DBText remaining = {1}, not on {2} = {3}",
    totalTxt, leftDb, FONT, wrongStyle));
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260610 - 6736 Tara Blvd, Jonesboro, GA 30236, USA\260610 - 6736 Tara Blvd R2.dwg
Message
Executed C3D-0304 (0 entities touched).
Entities
Duration
462 ms
Civil 3D
25.0.0.0

Log

font: GF_050 -> arial.ttf ("Arial")

  LAYOUT Model                       40 text entities
  LAYOUT 11X17                       13 text entities
  Well                               1 text entities
  Gas Valve                          1 text entities
  Drainage MH                        1 text entities
  Proposed Hyd                       3 text entities
  Water Shutoff                      3 text entities
  Sewer Manhole                      1 text entities
  Existing Hyd                       3 text entities
  Water Valve                        1 text entities
  Test Pit                           1 text entities
  Storm Manhole                      1 text entities
  A$C7a6e61a3                        1 text entities
  A$Cd6da300d                        1 text entities
  A$C4d757d29                        1 text entities
  A$C7ce714b5                        1 text entities
  A$C79a36f59                        1 text entities
  A$Cae1943e7                        1 text entities
  A$Ca44cd286                        1 text entities
  A$Ca5e8365b                        2 text entities
  A$C2CD672AE                        4 text entities
  CLOSEOUT                           1 text entities
  _TagCircle                         1 text entities
  A$Cb7e9aa3b                        1 text entities
  A$C3840e5d8                        32 text entities
  SP4                                1 text entities
  SP6                                1 text entities
  SP7                                1 text entities
  SP8                                1 text entities
  SP9                                1 text entities
  SP10                               1 text entities
  SP11                               1 text entities
  SP12                               1 text entities
  SP13                               1 text entities
  SP14                               1 text entities
  A$C0928e9a6                        1 text entities
  LAYOUT HOUSEDIM                    34 text entities
  *D155                              1 text entities
  *D156                              1 text entities
  *D157                              1 text entities
  *D158                              1 text entities
  *D159                              1 text entities
  *D160                              1 text entities
  *D161                              1 text entities
  *D162                              1 text entities
  *D163                              1 text entities
  *D164                              1 text entities
  *D165                              1 text entities
  *D166                              1 text entities
  SS_BLOCK_11X17                     20 text entities
  SS_LEGEND                          2 text entities
  11x17 COVER SHEET SS               40 text entities
  SS_BLOCK_11X17 (1)                 20 text entities
  SS_BLOCK_11X17 (2)                 20 text entities
  SS_BLOCK_11X17 (3)                 20 text entities
  *D175                              1 text entities
  A$C7bb5cf9f                        2 text entities
  A$Cf1f0f6b3                        1 text entities
  A$C573783bc                        1 text entities
  A$C6597917a                        1 text entities
  *D181                              1 text entities
  *D182                              1 text entities
  *D183                              1 text entities
  *D184                              1 text entities
  *D185                              1 text entities
  A$C9639ee2f                        1 text entities

converted 139 DBText -> MText, restyled 96 MText, restyled 73 attribute defs, skipped 112 on STAMP layers
VERIFY (whole drawing, excluding STAMP): 308 text entities, DBText remaining = 73, not on GF_050 = 0

Notes

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

No notes yet.