Author Topic: Erase Custom UCS  (Read 2765 times)

0 Members and 1 Guest are viewing this topic.

vegbruiser

  • Guest
Erase Custom UCS
« on: November 22, 2010, 09:11:48 AM »
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?

kaefer

  • Guest
Re: Erase Custom UCS
« Reply #1 on: November 22, 2010, 09:50:48 AM »
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?

Hi!

What are we missing that you can't erase this SysmbolTableRecord the Standard Way?

Or even the Work-Around-the-Erased-SymbolTableRecord-Bug Way?

See here http://www.caddzone.com/DBUtils.cs or the discussion here http://www.theswamp.org/index.php?topic=12123.msg150999#msg150999

vegbruiser

  • Guest
Re: Erase Custom UCS
« Reply #2 on: November 22, 2010, 09:58:41 AM »
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..  :-o

What's the standard way you're referring to BTW?

kaefer

  • Guest
Re: Erase Custom UCS
« Reply #3 on: November 22, 2010, 10:28:46 AM »
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..  :-o

What's the standard way you're referring to BTW?

Hi Alex,

just test for existance (SymboTable.Has), then open for write and say Good Bye (DBObject.Erase). That might fall flat on its face if there's a previously erased SymbolTableRecord with the same name.

F# for reference:
Code: [Select]
open Autodesk.AutoCAD.DatabaseServices
open Autodesk.AutoCAD.EditorInput
open Autodesk.AutoCAD.Runtime

type 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()
Cheers, Thorsten