C3DO-0832 · 261103 linework: fence (SS-X-FENCE) [C3D-LW1103-FENCE] done
Draws the fence from the FC/FL points 161-163-164-165-167 as a regular Polyline on SS-X-FENCE. Skips if that layer already has linework in the 261103 area.
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 fence from the FC / FL points 161-163-164-165-167 (west to east), regular Polyline on SS-X-FENCE.
const string LAYER="SS-X-FENCE"; Lyr(LAYER,7);
int have=0; foreach(ObjectId id in MS){ if(Tx.GetObject(id,OpenMode.ForRead) is Curve c && c.Layer==LAYER){ try{ var e=c.GeometricExtents; if(e.MaxPoint.X>2271300&&e.MinPoint.X<2272000&&e.MaxPoint.Y>1283250&&e.MinPoint.Y<1283700) have++; }catch{} } }
if(have>0){ Log(LAYER+" already has "+have+" curves in the 261103 area - nothing drawn"); Ed.Regen(); return; }
var V=new[]{new Point2d(2271574.6469,1283467.2475),new Point2d(2271666.3273,1283479.6394),new Point2d(2271711.3398,1283485.2954),new Point2d(2271886.1939,1283496.4397),new Point2d(2271930.5205,1283512.3521)};
var pl=new Polyline(); for(int i=0;i<V.Length;i++) pl.AddVertexAt(i,V[i],0,0,0); Put(MS,pl,LAYER);
Log("fence 161-163-164-165-167: "+pl.NumberOfVertices+" v, "+F(pl.Length)+"' on "+LAYER+" ("+pl.Handle+")");
Ed.Regen();
Result
Log
fence 161-163-164-165-167: 5 v, 360.186' on SS-X-FENCE (22021)
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.