Author Topic: Reset Scale List  (Read 3014 times)

0 Members and 1 Guest are viewing this topic.

cadpro

  • Guest
Reset Scale List
« on: February 13, 2008, 02:00:31 AM »
Hi all,

Can we reset the scale list in ACAD 2008 using .NET?

Thanks

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reset Scale List
« Reply #1 on: February 13, 2008, 04:27:04 AM »
Yes :

From either the registry ,
HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\<release>\<productKey>\Scale List

or
look at ;
 ... db.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");

Then have a look at the AnnotationScale Class

Then the ObjectContextCollection.AddContext(ObjectContext annotationScale);



I don't have time to bash and test code tonight, so see how you go with those leads ...

It will probably just be 1/2 page of code, so be sure to post it back.




kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reset Scale List
« Reply #2 on: February 16, 2008, 08:48:15 PM »

For anyone who thought about following up on this thread ...

Code: [Select]
        [CommandMethod("GetScaleList")]
        static public void getScaleList()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;                     
            try
            {
                ObjectContextManager oContextMan = db.ObjectContextManager;
                if (oContextMan != null)
                {
                     ObjectContextCollection occ =
                        oContextMan.GetContextCollection("ACDB_ANNOTATIONSCALES");

                    if (occ != null)
                    {
                        foreach (AnnotationScale anScale in occ)
                        {                           
                            ed.WriteMessage("\n" + anScale.Name);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(ex.ToString());
            }
        }

Code: [Select]
        [CommandMethod("AddScale")]
        static public void addScale()
        {                               
            try
            {
                ObjectContextManager oContextMan =
                    HostApplicationServices.WorkingDatabase.ObjectContextManager;
                             
                if (oContextMan != null)
                {                       
                    ObjectContextCollection occ =
                        oContextMan.GetContextCollection("ACDB_ANNOTATIONSCALES");                                     
                    if (occ != null)
                    {
                        if (!(occ.HasContext("CadProSuperScale 1:14")))
                        {
                            // new scale                     
                            AnnotationScale annotationScale = new AnnotationScale();
                            annotationScale.Name = "CadProSuperScale 1:14";
                            annotationScale.PaperUnits = 1;
                            annotationScale.DrawingUnits = 14;
                            //add to context collection                     
                            occ.AddContext(annotationScale);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
            }
        }
Piccys added :

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reset Scale List
« Reply #3 on: February 16, 2008, 10:06:24 PM »

... and to clear the list , except for the currently active scale ..

Code: [Select]
        [CommandMethod("ClearScaleList")]
        static public void ClearScaleList()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            try
            {
                ObjectContextManager oContextMan = db.ObjectContextManager;
                if (oContextMan != null)
                {                 
                    ObjectContextCollection occ =
                        oContextMan.GetContextCollection("ACDB_ANNOTATIONSCALES");
                    if (occ != null)
                    {
                        foreach (AnnotationScale anScale in occ)
                        {
                            if (!(occ.CurrentContext.Name.Equals(anScale.Name)))
                            {
                                ed.WriteMessage("\n" + anScale.Name + " : removed");
                                occ.RemoveContext(anScale.Name);
                               
                            }
                        }   
                    }
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(ex.ToString());
            }
        }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reset Scale List
« Reply #4 on: February 16, 2008, 10:26:14 PM »
just noticed the Output pane in the debugger ..
after running the _SCALELISTEDIT command in AutoCAD

The thread 0x17ac has exited with code 0 (0x0).
'acad.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0.....................
'acad.exe' (Managed): Loaded 'C:\ACAD2008\AcScaleList.dll'
'acad.exe' (Managed): Loaded 'C:\ACAD2008\en-US\AcScaleList.resources.dll'
The program '[5116] acad.exe: Managed' has exited with code 0 (0x0).

The function is defined in a NET assembly,
So it may be worthwhile having a look at the dll with Reflection.
I don't have time to look at the moment, so it's gone on the to-do list :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8825
  • AKA Daniel
Re: Reset Scale List
« Reply #5 on: February 16, 2008, 11:43:56 PM »
Wow! That sure is nice Kerry! I can use this  :kewl: