C3D-0309 · 260610 Tara Blvd: where does every store label sit right now (retry) error
Retry after CS1009 - the backslash-P in a Replace call needed a verbatim string. READ-ONLY: rebuilds the minimal fixture rectangles, lists every store MText with position, height, rotation, attachment, containing box and off-centre offset.
C# payload
// READ-ONLY: current state of every store MText, plus the minimal fixture rectangles, plus for
// each tag WHICH box contains it and how far off centre it is. Nothing is modified.
const double H = 0.33;
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
// rebuild minimal rectangles from FIXTURE segments
var hseg = new List<double[]>(); var vseg = new List<double[]>();
foreach (ObjectId id in ms) {
var ln = Tx.GetObject(id, OpenMode.ForRead) as Line;
if (ln == null || !ln.Layer.Equals("FIXTURE", StringComparison.OrdinalIgnoreCase)) continue;
double x1=Math.Round(ln.StartPoint.X,3), y1=Math.Round(ln.StartPoint.Y,3);
double x2=Math.Round(ln.EndPoint.X,3), y2=Math.Round(ln.EndPoint.Y,3);
if (Math.Abs(y1-y2)<0.01) hseg.Add(new double[]{y1,Math.Min(x1,x2),Math.Max(x1,x2)});
else if (Math.Abs(x1-x2)<0.01) vseg.Add(new double[]{x1,Math.Min(y1,y2),Math.Max(y1,y2)});
}
Func<double,double,double,bool> hasH = (y,xa,xb) => { foreach (var s in hseg) if (Math.Abs(s[0]-y)<0.02 && s[1]<=xa+0.02 && s[2]>=xb-0.02) return true; return false; };
Func<double,double,double,bool> hasV = (x,ya,yb) => { foreach (var s in vseg) if (Math.Abs(s[0]-x)<0.02 && s[1]<=ya+0.02 && s[2]>=yb-0.02) return true; return false; };
var xs=new List<double>(); foreach(var s in vseg) if(!xs.Exists(v=>Math.Abs(v-s[0])<0.02)) xs.Add(s[0]);
var ys=new List<double>(); foreach(var s in hseg) if(!ys.Exists(v=>Math.Abs(v-s[0])<0.02)) ys.Add(s[0]);
xs.Sort(); ys.Sort();
var all=new List<double[]>();
for(int i=0;i<xs.Count;i++) for(int j=i+1;j<xs.Count;j++)
for(int k=0;k<ys.Count;k++) for(int l=k+1;l<ys.Count;l++){
double x0=xs[i],x1b=xs[j],y0=ys[k],y1b=ys[l];
if(x1b-x0<0.5||y1b-y0<0.5) continue;
if(!hasH(y0,x0,x1b)||!hasH(y1b,x0,x1b)||!hasV(x0,y0,y1b)||!hasV(x1b,y0,y1b)) continue;
all.Add(new double[]{x0,y0,x1b,y1b});
}
var boxes=new List<double[]>();
foreach(var b in all){
bool bigger=false;
foreach(var o in all){ if(o==b) continue;
if(o[0]>=b[0]-0.01&&o[1]>=b[1]-0.01&&o[2]<=b[2]+0.01&&o[3]<=b[3]+0.01 &&
((o[2]-o[0])*(o[3]-o[1])) < ((b[2]-b[0])*(b[3]-b[1]))-0.01){ bigger=true; break; } }
if(!bigger) boxes.Add(b);
}
Log("minimal fixture boxes: " + boxes.Count);
Log("");
Log("=== EVERY STORE MTEXT, and where it sits ===");
int n=0;
foreach (ObjectId id in ms) {
var mt = Tx.GetObject(id, OpenMode.ForRead) as MText;
if (mt == null) continue;
double px=mt.Location.X, py=mt.Location.Y;
if (px<2261060||px>2261110||py<1391805||py>1391860) continue;
n++;
// which box contains the insertion point
int inBox=-1;
for(int i=0;i<boxes.Count;i++){ var b=boxes[i];
if(px>=b[0]-0.01&&px<=b[2]+0.01&&py>=b[1]-0.01&&py<=b[3]+0.01){ inBox=i; break; } }
string loc;
if(inBox>=0){ var b=boxes[inBox];
double cx=(b[0]+b[2])/2, cy=(b[1]+b[3])/2;
loc=string.Format("box{0} {1:F2}x{2:F2} off-centre dx={3:+0.00;-0.00} dy={4:+0.00;-0.00}",
inBox, b[2]-b[0], b[3]-b[1], px-cx, py-cy);
} else loc="NO BOX";
Log(string.Format("[{0}] ({1:F2},{2:F2}) h={3:F2} rot={4,3:F0} att={5,-12} \"{6}\" -> {7}",
mt.Handle, px, py, mt.TextHeight, mt.Rotation*180/Math.PI, mt.Attachment,
mt.Contents.Replace("\n"," ").Replace("\P"," "), loc));
}
Log("");
Log("store MText total: " + n);
Log("");
Log("=== BOXES ===");
for(int i=0;i<boxes.Count;i++){ var b=boxes[i];
Log(string.Format("box{0,-2} ({1:F2},{2:F2})-({3:F2},{4:F2}) {5:F2}x{6:F2} = {7:F2} sf centre ({8:F2},{9:F2})",
i, b[0],b[1],b[2],b[3], b[2]-b[0], b[3]-b[1], (b[2]-b[0])*(b[3]-b[1]), (b[0]+b[2])/2, (b[1]+b[3])/2)); }
Result
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.