.NET

Reply
Mentor
BrentBurgess1980
Posts: 161
Registered: ‎06-16-2008
Message 1 of 4 (258 Views)

Annotation Scale Sorting

258 Views, 3 Replies
12-20-2011 05:42 PM

I have the following code to add annocation scales.

 

        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());
                }
            }

 When I run the folllowing code

 

            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);

 it adds all of the scales, but they are displayed in this order
1:2
1:100
1:200
1:250
1:500
1:1000
1:2000
1:5000
1:10000
1:20000
1:50000
1:4
1:100000
1:200000
1:250000
1:500000
1:8
1:10
1:16
1:20
1:30
1:40
1:50
1:1

 

Is there a way to sort Annotation scales?

 

Thanks

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 2 of 4 (242 Views)

Re: Annotation Scale Sorting

12-21-2011 04:18 AM in reply to: BrentBurgess1980

I'm afraid you're out off luck

because of AutoCAD has its own sorting rule...

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
BrentBurgess1980
Posts: 161
Registered: ‎06-16-2008
Message 3 of 4 (227 Views)

Re: Annotation Scale Sorting

12-21-2011 04:14 PM in reply to: Hallex

Halex - I managed to find a solution to this, although it did take a lot of time trawling through the AcScaleList.dll in ILSpy to find that the Autodesk.AutoCAD.Internal as a ScaleListHelpers Class and used that to develop this, and it is sorted the way I was hoping.

 

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<string> ScaleListName = new List<string>();
        private static List<double> ScaleListNumerators = new List<double>();
        private static List<double> ScaleListDenominator = new List<double>();
        #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<string> GetScaleListString()
            {
            List<string> Temp = new List<string>();
            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<double> GetScaleNumerator()
            {
            List<double> Temp = new List<double>();
            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<double> GetScaleDenominator()
            {
            List<double> Temp = new List<double>();
            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
        }
    }

 So far it seems to be working ok... fingers crossed!

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 4 of 4 (212 Views)

Re: Annotation Scale Sorting

12-22-2011 03:32 AM in reply to: BrentBurgess1980

Holy Cow!

Ya da man

Accepted for 2010 :smileyhappy:

Regards,

 

Oleg

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community