Update 2013 references to 2022

Update 2013 references to 2022

jtm2020hyo
Collaborator Collaborator
539 Views
4 Replies
Message 1 of 5

Update 2013 references to 2022

jtm2020hyo
Collaborator
Collaborator

Good day, I tried update references in an old c# references to 2022 version, but no luck. (this code just renumber sheet sets incrementally)

 

/*
 * SheetSetTools. © Andrey Bushman, 2013
 * AutoCAD 2014 x64 Enu
 *
 * COMMANDS:
 * SS-RENUMBER-ALL - Update the numeration for all sheets in the all opened sheet sets:
 * numbering of each subgroup shall begin with 1.
 *
 * SS-RENUMBER-ALL-BASES-OF-FIRST - Update the numeration: to continue numbering on the
 * basis of the first element in the each subset (in the all opened sheet sets).
 *
 * AutoCAD references:
 * AcCoreMgd.dll
 * AcDbMgd.dll
 * AcMgd.dll
 * Interop.ACSMCOMPONENTS24Lib.dll
 */

using System;
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using App = Autodesk.AutoCAD.ApplicationServices;
using Db = Autodesk.AutoCAD.DatabaseServices;
using Ed = Autodesk.AutoCAD.EditorInput;
using Rtm = Autodesk.AutoCAD.Runtime;
using Comp = ACSMCOMPONENTS24Lib;

[assembly: Rtm.ExtensionApplication(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]
[assembly: Rtm.CommandClass(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]

namespace Bushman.AutoCAD.SheetSetTools
{

    public class SheetSetCommands : Rtm.IExtensionApplication
    {

        const String ns = "bush"; // namespace

        /// <summary>
        /// Update the numeration for all sheets in the all opened sheet sets: numbering of
        /// each subgroup shall begin with 1.
        /// </summary>
        [Rtm.CommandMethod(ns, "ss-renumber-all", Rtm.CommandFlags.Modal)]
        public void Renumber_All()
        {
            Renumber();
        }

        /// <summary>
        /// Update the numeration: to continue numbering on the basis of the first element
        /// in the each subset (in the all opened sheet sets).
        /// </summary>
        [Rtm.CommandMethod(ns, "ss-renumber-all-bases-of-first", Rtm.CommandFlags.Modal)]
        public void Renumber_all_bases_of_first()
        {
            Renumber(true);
        }

        /// <summary>
        /// To update numbering of all sheets in the all opened sheet sets.
        /// </summary>
        /// <param name="continue_numbering">True - to continue numbering on the basis
        /// of the first element in the each subset (in the all opened sheet sets);
        /// False - Numbering of each subgroup shall begin with 1 (in the all opened
        /// sheet sets).</param>
        void Renumber(Boolean continue_numbering = false)
        {
            App.Document doc = cad.DocumentManager.MdiActiveDocument;
            Db.Database db = doc.Database;
            Ed.Editor ed = doc.Editor;
            Comp.AcSmSheetSetMgr mng = new Comp.AcSmSheetSetMgr();
            Comp.IAcSmEnumDatabase enumerator = mng.GetDatabaseEnumerator();
            enumerator.Reset();
            Comp.AcSmDatabase smDb = null;
            while ((smDb = enumerator.Next()) != null)
            {
                smDb.LockDb(db);
                String fname = smDb.GetFileName();
                Comp.AcSmSheetSet sheetset = smDb.GetSheetSet();
                String name = sheetset.GetName();
                String descr = sheetset.GetDesc();
                ed.WriteMessage("\nSheet Set name: {0}\n", name);
                Int32 ren_count = 0; // count of renamed sheets.
                Comp.IAcSmEnumComponent encomp = sheetset.GetSheetEnumerator();
                encomp.Reset();
                Comp.IAcSmComponent component = null;
                while ((component = encomp.Next()) != null)
                {
                    ProcessElement(ed, component, ref ren_count, continue_numbering);
                }
                encomp.Reset();
                smDb.UnlockDb(db, true);
                ed.WriteMessage("Renumbered sheets count: {0}\n", ren_count);
            }
            enumerator.Reset();
        }

        /// <summary>
        ///  Recursive processing of the elements: change the sheet's number.
        /// </summary>
        /// <param name="ed">An Editor for the output.</param>
        /// <param name="component">Component of Sheet Set.</param>
        /// <param name="ren_count">The count of renumbered sheets in the sheet set.</param>
        /// <param name="continue_numbering">True - to continue numbering on the basis
        /// of the first element in the each subset (in the all opened sheet sets);
        /// False - Numbering of each subgroup shall begin with 1 (in the all opened
        /// sheet sets).</param>
        void ProcessElement(Ed.Editor ed, Comp.IAcSmComponent component,
            ref Int32 ren_count, Boolean continue_numbering)
        {
            component.GetDirectlyOwnedObjects(out Array array);
            if (array != null)
            {
                Int32 sheet_number = 1;
                Boolean basis_of_first = continue_numbering;
                foreach (var item in array)
                {
                    if (item is Comp.IAcSmSubset)
                    {
                        ProcessElement(ed, (Comp.IAcSmSubset)item, ref ren_count, continue_numbering);
                    }
                    else if (item is Comp.IAcSmSheet sheet)
                    {
                        String cur_str_value = sheet.GetNumber();
                        Boolean is_int32 = Int32.TryParse(cur_str_value, out int int_value);

                        if (!is_int32 || (!basis_of_first && int_value != sheet_number))
                        {
                            sheet.SetNumber(sheet_number.ToString());
                            ++ren_count;
                        }
                        else if (basis_of_first)
                        {
                            sheet_number = int_value;
                        }
                        ++sheet_number;
                        basis_of_first = false;
                    }
                    else if (item is Comp.IAcSmPersist persist)
                    {
                    }
                    else
                    {
                        ed.WriteMessage("Unknown object: {0}", item.GetType().ToString());
                    }
                }
            }
        }

        #region IExtensionApplication Members

        public void Initialize()
        {
            App.Document doc = cad.DocumentManager.MdiActiveDocument;
            Ed.Editor ed = doc.Editor;
            ed.WriteMessage("\nSheetSetTools. © Andrey Bushman, 2013\n\n");
        }

        public void Terminate()
        {
            // Empty body.
        }
        #endregion
    }
}

 

 

here the errors:

 

 

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Message	IDE0038	Use pattern matching	Project-AMEP1	C:\JTM\VS\CS\AMEP1\Solution-AMEP1\Project-AMEP1\SS-Renumber.cs	117	Active
Warning		Could not resolve this reference. Could not locate the assembly "aecUIBaseMgd". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.	Project-AMEP1			
Warning		Could not resolve this reference. Could not locate the assembly "aecUtilityMgd". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.	Project-AMEP1			
Error	CS0579	Duplicate 'Rtm.ExtensionApplication' attribute	Project-AMEP1	C:\JTM\VS\CS\AMEP1\Solution-AMEP1\Project-AMEP1\SS-Renumber.cs	27	Active
Warning		The referenced component 'aecUIBaseMgd' could not be found.	Project-AMEP1			
Warning		The referenced component 'aecUtilityMgd' could not be found.	Project-AMEP1			
Message	IDE0059	Unnecessary assignment of a value to 'persist'	Project-AMEP1	C:\JTM\VS\CS\AMEP1\Solution-AMEP1\Project-AMEP1\SS-Renumber.cs	138	Active	Avoid unnecessary value assignments in your code, as these likely indicate redundant value computations. If the value computation is not redundant and you intend to retain the assignment, then change the assignment target to a local variable whose name starts with an underscore and is optionally followed by an integer, such as '_', '_1', '_2', etc. These are treated as special discard symbol names.

 

 

anyone can help?

0 Likes
540 Views
4 Replies
Replies (4)
Message 2 of 5

Alexander.Rivilis
Mentor
Mentor

Delete or comment line:

[assembly: Rtm.ExtensionApplication(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 5

norman.yuan
Mentor
Mentor

It seems to me that the error you get has nothing to do with the code you showed. I guess you downloaded/copied the project from somewhere and the project has references to older version of  AecUIBaseMgd.dll and AecUtilityMgd.dll for Acad Arch/MEP. 

 

If your goal is only to deal with Sheet Set, and nothing specific to Acad Arch/MEP, you can simply remove these references. Or, if you use Acad Arch/MEP and need to work with Arch/MEP features, then you need to update the references with corresponding version.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 5

jtm2020hyo
Collaborator
Collaborator

I isolated the SS-Renumber project to an individual project and now works. but was need //Comment the line in myPlugin.cs that was created by the AutoCAD Net Wizard.

 



comparison, SS-Renumber.cs:

 

[assembly: Rtm.ExtensionApplication(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]

 

myPlugin.cs

 

// This line is not mandatory, but improves loading performances
//[assembly: ExtensionApplication(typeof(ProjectACA1.MyPlugin))]

 

I wish to keep all code usable in myPlugin.cs and keep using SS-Renumber.cs code without errors at the same project-solution, Any suggestion?

0 Likes
Message 5 of 5

jtm2020hyo
Collaborator
Collaborator

those references was added automatically by the AutoCAD Net Wizard. Is a bit confuse because until I was researching those mentioned references was unified in another DLL called AECcoreMLD or something like this.

... just curiously, why was added in the ACA 2022 Net Wizard if already is not supported those references?

0 Likes