← Inbox

C3D-SCALEFIX · Fix scales to 1:10, 1:20 ... 1:100 done

Replace the 1"=N' (x12) scales with clean 1:10..1:100 (paper 1 : drawing N). Set current to 1:20. C3D-26.

Script file
C3D-SCALEFIX.cs
Target
SS_Outfall_260612_SHEET.dwg · model space
Author
claude
Approved
yes · reviewer
Timeout
60s

C# payload

// Redo engineering scales as 1:10, 1:20, ... 1:100 (paper 1 : drawing 10..100, NOT x12).
// Remove the 1"=N' (1:120 etc) versions I added, replace with clean 1:N. Keep 1"=1' and 1:1.
using System;
using System.Linq;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;

var db = Db;
var ocm = db.ObjectContextManager;
var coll = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
if (coll == null){ Log("no scale collection"); return; }

var keep = new HashSet<string>(StringComparer.OrdinalIgnoreCase){ "1\" = 1'", "1:1" };

// desired: name "1:N", paper 1 : drawing N, for N = 10..100 by 10
var want = new List<(string name,double drawing)>();
for (int n=10; n<=100; n+=10) want.Add(($"1:{n}", n));
var wantNames = new HashSet<string>(want.Select(w=>w.name), StringComparer.OrdinalIgnoreCase);

// set a safe current scale before removing
try { var one=coll.GetContext("1\" = 1'"); if(one!=null) db.Cannoscale=(Autodesk.AutoCAD.DatabaseServices.AnnotationScale)one; } catch(System.Exception ex){ Log($"pre-set: {ex.Message}"); }

// remove anything not in keep and not already a desired 1:N
var toRemove=new List<string>();
foreach(ObjectContext oc in coll){ var nm=oc.Name; if(keep.Contains(nm)||wantNames.Contains(nm)) continue; toRemove.Add(nm); }
int removed=0;
foreach(var nm in toRemove){ try{ coll.RemoveContext(nm); removed++; }catch(System.Exception ex){ Log($"  rm '{nm}': {ex.Message}"); } }
Log($"removed {removed}");

// add 1:N
int added=0;
foreach(var w in want){
    if(coll.GetContext(w.name)!=null) continue;
    try{ var sc=new Autodesk.AutoCAD.DatabaseServices.AnnotationScale{ Name=w.name, PaperUnits=1.0, DrawingUnits=w.drawing }; coll.AddContext(sc); added++; }
    catch(System.Exception ex){ Log($"  add '{w.name}': {ex.Message}"); }
}
Log($"added {added}");

// set current to 1:20
try{ var s=coll.GetContext("1:20"); if(s!=null) db.Cannoscale=(Autodesk.AutoCAD.DatabaseServices.AnnotationScale)s; }catch(System.Exception ex){ Log($"set: {ex.Message}"); }

Log("SCALE LIST NOW:");
foreach(ObjectContext oc in coll){ var sc=oc as Autodesk.AutoCAD.DatabaseServices.AnnotationScale; Log($"  {oc.Name}  (paper {sc?.PaperUnits} : drawing {sc?.DrawingUnits})"); }
Log($"CANNOSCALE = {db.Cannoscale?.Name}");
Log("DONE.");

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\SS_Outfall_260612_SHEET.dwg
Message
Executed C3D-SCALEFIX (0 entities touched).
Entities
Duration
370 ms
Civil 3D
25.0.0.0

Log

  rm '1" = 10'': eObjectIsReferenced
removed 9
added 10
SCALE LIST NOW:
  1" = 1'  (paper 1 : drawing 1)
  1:10  (paper 1 : drawing 10)
  1:20  (paper 1 : drawing 20)
  1:30  (paper 1 : drawing 30)
  1:40  (paper 1 : drawing 40)
  1:50  (paper 1 : drawing 50)
  1:60  (paper 1 : drawing 60)
  1:70  (paper 1 : drawing 70)
  1:80  (paper 1 : drawing 80)
  1" = 10'  (paper 1 : drawing 120)
  1:90  (paper 1 : drawing 90)
  1:100  (paper 1 : drawing 100)
  1:1  (paper 1 : drawing 1)
CANNOSCALE = 1:20
DONE.

Notes

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

No notes yet.