← Inbox

C3DO-0759 · 261101: gas meter symbol reads GM [C3D-GASMETER] done

Copy the Gas Valve symbol block to a new 'Gas Meter' block with its GV text changed to GM, point the 'Gas METER' point style at it, and swap the legend's gas meter symbol (2193E) to it. Gas Valve block and style untouched.

Script file
C3DO-0759.cs
Target
261101 - 5491 Roswell Rd NE R2.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

var bt=(BlockTable)Tx.GetObject(Db.BlockTableId,OpenMode.ForRead);
if(!bt.Has("Gas Valve")){ Log("STOP - no Gas Valve block"); return; }
var gv=(BlockTableRecord)Tx.GetObject(bt["Gas Valve"],OpenMode.ForRead);
ObjectId gmId;
if(bt.Has("Gas Meter")){ gmId=bt["Gas Meter"]; Log("Gas Meter block already exists - reusing it"); }
else {
 bool hasGV=false; foreach(ObjectId id in gv){ var t=Tx.GetObject(id,OpenMode.ForRead) as DBText; if(t!=null&&t.TextString.Trim()=="GV") hasGV=true; }
 if(!hasGV){ Log("STOP - Gas Valve block has no 'GV' text"); return; }
 var gm=new BlockTableRecord(); gm.Name="Gas Meter"; gm.Origin=gv.Origin;
 bt.UpgradeOpen(); gmId=bt.Add(gm); Tx.AddNewlyCreatedDBObject(gm,true);
 int n=0; foreach(ObjectId id in gv){ var e=(Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id,OpenMode.ForRead); var c=(Autodesk.AutoCAD.DatabaseServices.Entity)e.Clone();
  var t=c as DBText; if(t!=null&&t.TextString.Trim()=="GV") t.TextString="GM";
  gm.AppendEntity(c); Tx.AddNewlyCreatedDBObject(c,true); n++; }
 Log("new block Gas Meter: "+n+" pieces copied from Gas Valve, text GV -> GM"); }
var gmb=(BlockTableRecord)Tx.GetObject(gmId,OpenMode.ForRead); string txt=""; foreach(ObjectId id in gmb){ var t=Tx.GetObject(id,OpenMode.ForRead) as DBText; if(t!=null) txt+=t.TextString; }
Autodesk.Civil.DatabaseServices.Styles.PointStyle ps=null;
foreach(ObjectId id in CivilDoc.Styles.PointStyles){ var s=(Autodesk.Civil.DatabaseServices.Styles.PointStyle)Tx.GetObject(id,OpenMode.ForRead); if(s.Name=="Gas METER") ps=s; }
if(ps==null){ Log("STOP - point style Gas METER not found"); throw new Exception("rolled back"); }
string was=ps.MarkerSymbolName; ps.UpgradeOpen(); ps.MarkerSymbolName="Gas Meter";
Log("point style Gas METER symbol: "+was+" -> "+ps.MarkerSymbolName+(ps.MarkerSymbolName=="Gas Meter"?" (verified)":" (NOT SET)"));
ObjectId rid; Db.TryGetObjectId(new Handle(Convert.ToInt64("2193E",16)),out rid);
if(rid.IsNull||rid.IsErased){ Log("legend gas meter symbol 2193E not found - legend not changed"); }
else { var br=(BlockReference)Tx.GetObject(rid,OpenMode.ForWrite); string bw=br.Name; br.BlockTableRecord=gmId; Log("legend symbol 2193E: "+bw+" -> "+br.Name+(br.Name=="Gas Meter"?" (verified)":"")); }
Log("Gas Meter block text reads '"+txt+"'");
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\261101 - Project\261101 - 5491 Roswell Rd NE R2.dwg
Message
Executed C3DO-0759 (0 entities touched).
Entities
—
Duration
417 ms
Civil 3D
25.0.0.0

Log

new block Gas Meter: 5 pieces copied from Gas Valve, text GV -> GM
point style Gas METER symbol: Gas Valve -> Gas Meter (verified)
legend symbol 2193E: Gas Valve -> Gas Meter (verified)
Gas Meter block text reads 'GM'

Notes

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

No notes yet.