0 Members and 1 Guest are viewing this topic.
public void RemoveCustomUCS() { Document doc = AcadApp.DocumentManager.MdiActiveDocument; using (Database tmpdb = doc.Database) { using (Transaction tmptr = tmpdb.TransactionManager.StartTransaction()) { UcsTable ucstbl = tmptr.GetObject(tmpdb.UcsTableId, OpenMode.ForRead) as UcsTable; foreach (ObjectId UcsId in ucstbl) { UcsTableRecord tmpUcs = tmptr.GetObject(UcsId,OpenMode.ForRead) as UcsTableRecord; if (Regex.IsMatch(tmpUcs.Name.ToString(),"*[color=red]CustomUCSNAME[/color]*")) { UcsTableRecord HasUcs = (UcsTableRecord)tmptr.GetObject(ucstbl[tmpUcs.Name], OpenMode.ForWrite, true); HasUcs.Erase(); } } tmptr.Commit(); } } }
I figured this was worth sharing this as no one else seems to have posted how to do this..I intend to use this as part of my CreateLayouts routine here.Code: [Select]public void RemoveCustomUCS() { Document doc = AcadApp.DocumentManager.MdiActiveDocument; using (Database tmpdb = doc.Database) { using (Transaction tmptr = tmpdb.TransactionManager.StartTransaction()) { UcsTable ucstbl = tmptr.GetObject(tmpdb.UcsTableId, OpenMode.ForRead) as UcsTable; foreach (ObjectId UcsId in ucstbl) { UcsTableRecord tmpUcs = tmptr.GetObject(UcsId,OpenMode.ForRead) as UcsTableRecord; if (Regex.IsMatch(tmpUcs.Name.ToString(),"*[color=red]CustomUCSNAME[/color]*")) { UcsTableRecord HasUcs = (UcsTableRecord)tmptr.GetObject(ucstbl[tmpUcs.Name], OpenMode.ForWrite, true); HasUcs.Erase(); } } tmptr.Commit(); } } }Is there any better way of doing this that I have missed?
Thanks Kaefer, I wasn't aware of those posts.If it had been labelled as "Use this to erase X" then I might have found it myself.. What's the standard way you're referring to BTW?
open Autodesk.AutoCAD.DatabaseServicesopen Autodesk.AutoCAD.EditorInputopen Autodesk.AutoCAD.Runtimetype acApp = Autodesk.AutoCAD.ApplicationServices.Application[<CommandMethod "RemoveUCS">]let removeUCS() = let doc = acApp.DocumentManager.MdiActiveDocument let ed = doc.Editor let db = doc.Database let pstr = new PromptStringOptions( "\nEnter UCS name: ", AllowSpaces = true ) |> ed.GetString if pstr.Status = PromptStatus.OK then use tr = db.TransactionManager.StartTransaction() let ut = tr.GetObject(db.UcsTableId, OpenMode.ForRead) :?> UcsTable if ut.Has pstr.StringResult then let utr = tr.GetObject(ut.[pstr.StringResult], OpenMode.ForWrite) :?> SymbolTableRecord utr.Erase() tr.Commit()