C3DO-0831 · 261103: COGO points onto 0-<CODE> layers by description [C3D-PTLAYERS] done
Moves every COGO point on layer 0 to a layer named 0-<first word of its description> (0-TBC, 0-CL, 0-EP, 0-FL, ...), creating the layers. Points not on layer 0 are left alone.
C# payload
string F(double v)=>v.ToString("0.###");
ObjectId H(string h)=>Db.GetObjectId(false,new Handle(Convert.ToInt64(h,16)),0);
ObjectId Lyr(string name,short c){ var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForRead); if(lt.Has(name)) return lt[name]; lt.UpgradeOpen(); var r=new LayerTableRecord{Name=name,Color=Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci,c)}; var id=lt.Add(r); Tx.AddNewlyCreatedDBObject(r,true); Log("layer created "+name); return id; }
ObjectId Put(BlockTableRecord btr, Autodesk.AutoCAD.DatabaseServices.Entity e, string layer){ e.SetDatabaseDefaults(Db); e.Layer=layer; var id=btr.AppendEntity(e); Tx.AddNewlyCreatedDBObject(e,true); return id; }
var LM=LayoutManager.Current;
BlockTableRecord PS(string name){ var l=(Layout)Tx.GetObject(LM.GetLayoutId(name),OpenMode.ForRead); return (BlockTableRecord)Tx.GetObject(l.BlockTableRecordId,OpenMode.ForWrite); }
var BT=(BlockTable)Tx.GetObject(Db.BlockTableId,OpenMode.ForRead);
var MS=(BlockTableRecord)Tx.GetObject(BT[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
bool HasText(BlockTableRecord btr,string contains){ foreach(ObjectId id in btr){ var o=Tx.GetObject(id,OpenMode.ForRead); if(o is MText m && m.Contents.Contains(contains)) return true; if(o is DBText t && t.TextString.Contains(contains)) return true; } return false; }
// 261103: COGO points off layer 0 onto one layer per description code (first word), 0-<CODE>, so each set turns off on its own.
var moved=new Dictionary<string,int>(); int skip=0;
foreach(ObjectId id in MS){
if(!(Tx.GetObject(id,OpenMode.ForRead) is Autodesk.Civil.DatabaseServices.CogoPoint cp)) continue;
if(cp.Layer!="0"){ skip++; continue; }
var d=(cp.RawDescription??"").Trim(); var code=d.Split(new[]{' '},StringSplitOptions.RemoveEmptyEntries).FirstOrDefault()??"NODESC";
code=new string(code.ToUpper().Select(ch=>char.IsLetterOrDigit(ch)?ch:'_').ToArray());
var lay="0-"+code; Lyr(lay,7);
cp.UpgradeOpen(); cp.Layer=lay; moved[lay]=moved.TryGetValue(lay,out var n)?n+1:1;
}
foreach(var kv in moved.OrderBy(k=>k.Key)) Log(kv.Key+": "+kv.Value+" pts (verified "+kv.Value+")");
Log("points already off layer 0, left alone: "+skip);
Ed.Regen();
Result
Log
layer created 0-EP layer created 0-CL layer created 0-WHITE layer created 0-TBC layer created 0-WV layer created 0-SSMH layer created 0-IPF layer created 0-UNDRG layer created 0-FL layer created 0-HENRY layer created 0-FC layer created 0-WM layer created 0-SW 0-CL: 10 pts (verified 10) 0-EP: 11 pts (verified 11) 0-FC: 1 pts (verified 1) 0-FL: 2 pts (verified 2) 0-HENRY: 1 pts (verified 1) 0-IPF: 4 pts (verified 4) 0-SSMH: 2 pts (verified 2) 0-SW: 10 pts (verified 10) 0-TBC: 38 pts (verified 38) 0-UNDRG: 4 pts (verified 4) 0-WHITE: 5 pts (verified 5) 0-WM: 1 pts (verified 1) 0-WV: 3 pts (verified 3) points already off layer 0, left alone: 0
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.