<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Annotation Scale Sorting in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3271873#M57931</link>
    <description>&lt;P&gt;Holy Cow!&lt;/P&gt;&lt;P&gt;Ya da man&lt;/P&gt;&lt;P&gt;Accepted for 2010 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oleg&lt;/P&gt;</description>
    <pubDate>Thu, 22 Dec 2011 11:32:30 GMT</pubDate>
    <dc:creator>Hallex</dc:creator>
    <dc:date>2011-12-22T11:32:30Z</dc:date>
    <item>
      <title>Annotation Scale Sorting</title>
      <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3270357#M57928</link>
      <description>&lt;P&gt;I have the following code to add annocation scales.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static void AddScale(string Name, double PaperUnits, double DrawingUnits)
            {
            try
                {
                ObjectContextManager ocm = HostApplicationServices.WorkingDatabase.ObjectContextManager;

                if (ocm != null)
                    {
                    ObjectContextCollection occ =
                        ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
                    if (occ != null)
                        {
                        if (!(occ.HasContext(Name)))
                            {
                            // new scale                     
                            AnnotationScale annotationScale = new AnnotationScale();
                            annotationScale.Name = Name;
                            annotationScale.PaperUnits = PaperUnits;
                            annotationScale.DrawingUnits = DrawingUnits;
                            Editor ed = AcApp.DocumentManager.MdiActiveDocument.Editor;
                            //ed.WriteMessage(string.Format("\n{0}", annotationScale.Name));

                            //add to context collection                     
                            occ.AddContext(annotationScale);
                            }
                        }
                    }
                }
            catch (System.Exception ex)
                {
                AcApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
                }
            }

        public static void ClearScaleList()
            {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcApp.DocumentManager.MdiActiveDocument.Editor;
            try
                {
                ObjectContextManager ocm = db.ObjectContextManager;
                if (ocm != null)
                    {
                    ObjectContextCollection occ = ocm.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());
                }
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;When I run the folllowing code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            Setup.ScaleList.ClearScaleList();
            Setup.ScaleList.AddScale("1:1", 1,1);
            Setup.ScaleList.AddScale("1:2", 1, 1);
            Setup.ScaleList.AddScale("1:4", 1, 1);
            Setup.ScaleList.AddScale("1:8", 1, 1);
            Setup.ScaleList.AddScale("1:10", 1, 1);
            Setup.ScaleList.AddScale("1:16", 1, 1);
            Setup.ScaleList.AddScale("1:20", 1, 1);
            Setup.ScaleList.AddScale("1:30", 1, 1);
            Setup.ScaleList.AddScale("1:40", 1, 1);
            Setup.ScaleList.AddScale("1:50", 1, 1);
            Setup.ScaleList.AddScale("1:100", 1, 1);
            Setup.ScaleList.AddScale("1:200", 1, 1);
            Setup.ScaleList.AddScale("1:250", 1, 1);
            Setup.ScaleList.AddScale("1:500", 1, 1);
            Setup.ScaleList.AddScale("1:1000", 1, 1);
            Setup.ScaleList.AddScale("1:2000", 1, 1);
            Setup.ScaleList.AddScale("1:5000", 1, 1);
            Setup.ScaleList.AddScale("1:10000", 1, 1);
            Setup.ScaleList.AddScale("1:20000", 1, 1);
            Setup.ScaleList.AddScale("1:50000", 1, 1);
            Setup.ScaleList.AddScale("1:100000", 1, 1);
            Setup.ScaleList.AddScale("1:200000", 1, 1);
            Setup.ScaleList.AddScale("1:250000", 1, 1);
            Setup.ScaleList.AddScale("1:500000", 1, 1);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;it adds all of the scales, but they are displayed in this order&lt;BR /&gt;1:2&lt;BR /&gt;1:100&lt;BR /&gt;1:200&lt;BR /&gt;1:250&lt;BR /&gt;1:500&lt;BR /&gt;1:1000&lt;BR /&gt;1:2000&lt;BR /&gt;1:5000&lt;BR /&gt;1:10000&lt;BR /&gt;1:20000&lt;BR /&gt;1:50000&lt;BR /&gt;1:4&lt;BR /&gt;1:100000&lt;BR /&gt;1:200000&lt;BR /&gt;1:250000&lt;BR /&gt;1:500000&lt;BR /&gt;1:8&lt;BR /&gt;1:10&lt;BR /&gt;1:16&lt;BR /&gt;1:20&lt;BR /&gt;1:30&lt;BR /&gt;1:40&lt;BR /&gt;1:50&lt;BR /&gt;1:1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to sort Annotation scales?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2011 01:42:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3270357#M57928</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2011-12-21T01:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Annotation Scale Sorting</title>
      <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3270703#M57929</link>
      <description>&lt;P&gt;I'm afraid you're out off luck&lt;/P&gt;&lt;P&gt;because of&amp;nbsp;AutoCAD has its own sorting rule...&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2011 12:18:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3270703#M57929</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-12-21T12:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Annotation Scale Sorting</title>
      <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3271453#M57930</link>
      <description>&lt;P&gt;Halex - I managed to find a solution to this, although it did take a lot of time trawling through the AcScaleList.dll in&amp;nbsp;ILSpy to find that the&amp;nbsp;Autodesk&lt;SPAN style="color: #006400;"&gt;.&lt;/SPAN&gt;AutoCAD&lt;SPAN style="color: #006400;"&gt;.&lt;/SPAN&gt;Internal as a ScaleListHelpers Class and used that to develop this, and it is sorted the way I was hoping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Internal;
using AcApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace Setup
    {
    public class ScaleLists
        {
        #region "Members"
        private static List&amp;lt;string&amp;gt; ScaleListName = new List&amp;lt;string&amp;gt;();
        private static List&amp;lt;double&amp;gt; ScaleListNumerators = new List&amp;lt;double&amp;gt;();
        private static List&amp;lt;double&amp;gt; ScaleListDenominator = new List&amp;lt;double&amp;gt;();
        #endregion

        #region "Public Methods"

        public static void AddScaleLists()
            {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcApp.DocumentManager.MdiActiveDocument.Editor;

            ScaleListName.Clear();
            ScaleListNumerators.Clear();
            ScaleListDenominator.Clear();
            
            //only runs if the GetScales returns a false value
            ScaleListName = GetScaleListString();
            ScaleListNumerators = GetScaleNumerator();
            ScaleListDenominator = GetScaleDenominator();

            ScaleListHelpers.updateScaleList(ScaleListName, ScaleListName, ScaleListNumerators, ScaleListDenominator, ScaleListDenominator.Count);
            }

        #endregion

        #region "Private Methods"
        private static List&amp;lt;string&amp;gt; GetScaleListString()
            {
            List&amp;lt;string&amp;gt; Temp = new List&amp;lt;string&amp;gt;();
            Temp.Add("1:1");
            Temp.Add("1:2");
            Temp.Add("1:4");
            Temp.Add("1:8");
            Temp.Add("1:10");
            Temp.Add("1:16");
            Temp.Add("1:20");
            Temp.Add("1:30");
            Temp.Add("1:40");
            Temp.Add("1:50");
            Temp.Add("1:100");
            Temp.Add("1:200");
            Temp.Add("1:250");
            Temp.Add("1:500");
            Temp.Add("1:1000");
            Temp.Add("1:2000");
            Temp.Add("1:5000");
            Temp.Add("1:10000");
            Temp.Add("1:20000");
            Temp.Add("1:50000");
            Temp.Add("1:100000");
            Temp.Add("1:200000");
            Temp.Add("1:250000");
            Temp.Add("1:500000");
            return Temp;
            }

        private static List&amp;lt;double&amp;gt; GetScaleNumerator()
            {
            List&amp;lt;double&amp;gt; Temp = new List&amp;lt;double&amp;gt;();
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            Temp.Add(1);
            return Temp;
            }

        private static List&amp;lt;double&amp;gt; GetScaleDenominator()
            {
            List&amp;lt;double&amp;gt; Temp = new List&amp;lt;double&amp;gt;();
            Temp.Add(1);
            Temp.Add(2);
            Temp.Add(4);
            Temp.Add(8);
            Temp.Add(10);
            Temp.Add(16);
            Temp.Add(20);
            Temp.Add(30);
            Temp.Add(40);
            Temp.Add(50);
            Temp.Add(100);
            Temp.Add(200);
            Temp.Add(250);
            Temp.Add(500);
            Temp.Add(1000);
            Temp.Add(2000);
            Temp.Add(5000);
            Temp.Add(10000);
            Temp.Add(20000);
            Temp.Add(50000);
            Temp.Add(100000);
            Temp.Add(200000);
            Temp.Add(250000);
            Temp.Add(500000);
            return Temp;
            }
        #endregion
        }
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;So far it seems to be working ok... fingers crossed!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2011 00:14:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3271453#M57930</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2011-12-22T00:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Annotation Scale Sorting</title>
      <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3271873#M57931</link>
      <description>&lt;P&gt;Holy Cow!&lt;/P&gt;&lt;P&gt;Ya da man&lt;/P&gt;&lt;P&gt;Accepted for 2010 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oleg&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2011 11:32:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/3271873#M57931</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-12-22T11:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Annotation Scale Sorting</title>
      <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/5345373#M57932</link>
      <description>&lt;P&gt;I know this is an old post, but it helped me a lot! Thanks!&lt;/P&gt;&lt;P&gt;One thing i noticed - if it helps anyone - is that if you run the first posted code twice, it will sort them in order.&amp;nbsp; Only the first run seems randomly scattered. I just added another function to run the main function twice and it seems to work, sorting them properly.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2014 19:25:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/5345373#M57932</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-10-17T19:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Annotation Scale Sorting</title>
      <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/6524508#M57933</link>
      <description>&lt;P&gt;Thanks!&amp;nbsp;&amp;nbsp;&amp;nbsp; Just the post I need!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:29:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/6524508#M57933</guid>
      <dc:creator>agaalen</dc:creator>
      <dc:date>2016-08-26T08:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Annotation Scale Sorting</title>
      <link>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/12113618#M57934</link>
      <description>&lt;P&gt;Did work very well. tks&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 00:37:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/annotation-scale-sorting/m-p/12113618#M57934</guid>
      <dc:creator>beltrao4DL3P</dc:creator>
      <dc:date>2023-07-20T00:37:44Z</dc:date>
    </item>
  </channel>
</rss>

