.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to recycle an 2014 VB.NET?

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
jtm2020hyo
2653 Views, 11 Replies

How to recycle an 2014 VB.NET?

I need to update an old 2014 VB.net to renumber sheet sets to Autocad 2020.

I'm using VS 2017 and VS 2019.

I tried to do changes to the code as was recommended in other posts but I always have errors.

 

Original post :

http://www.theswamp.org/index.php?topic=45672.msg508180#msg508180

image.png

 

here my version:

///tlbimp acsmcomponents19.tlb /out:Interop.ACSMCOMPONENTS19Lib.dll  /namespace:AcSm  /machine:x64
///tlbimp acsmcomponents23.tlb /out:Interop.ACSMCOMPONENTS23Lib.dll  /namespace:AcSm  /machine:x64
///"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\TlbImp.exe" "C:\Autodesk\ObjectARX_for_AutoCAD_2020_Win_64_bit\inc-x64\acsmcomponents23.tlb" /out:"C:\Autodesk\ObjectARX_for_AutoCAD_2020_Win_64_bit\inc-x64\Interop.ACSMCOMPONENTS23Lib.dll"  /namespace:AcSm  /machine:x64

/*
 * SheetSetTools. © Andrey Bushman, 2013, original
 * Modified to work with AUTOCAD 2020 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.ACSMCOMPONENTS23Lib.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 = ACSMCOMPONENTS23Lib;
 
[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) {
            Array array = null;
            component.GetDirectlyOwnedObjects(out 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) {
                        Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;
 
                        String cur_str_value = sheet.GetNumber();
                        Int32 int_value = 0;
                        Boolean is_int32 = Int32.TryParse(cur_str_value, out 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) {
                        Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
                    }
                    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
    }
}
 

So, How can I do it? (If possible, explain with a step to step)

 

11 REPLIES 11
Message 2 of 12
_gile
in reply to: jtm2020hyo

Multiplying topics does not make it easy to understand what you are trying to do for those who are trying to help you as well as for those who have the same type of request.

 

You cannot easily use existing .NET code if you do not know the basics of .NET and the way to use it with AutoCAD (you can start reading this topic).

 

In your case:

  1. Start a new class library project in Visual Studio 2017 (or upper)
  2. Target the .NET Framework 4.7
  3. Add accoremgd.dll, acdbmgd.dll and acmgd.dll references from 'ObjectARX 2020\inc' folder
  4. Set the Copy Local property of these reference to False
  5. Add acsmcomponents23.tlb reference from 'ObjectARX 2020\inc-x64' folder
  6. Paste the original code in the class crated by Visual Studio
  7. Replace: 'using Comp = ACSMCOMPONENTS19lib' with 'using Comp = ACSMCOMPONENTS23lib'

That's all, the proct would compile without error.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 12
jtm2020hyo
in reply to: _gile


@_gile wrote:

Multiplying topics does not make it easy to understand what you are trying to do for those who are trying to help you as well as for those who have the same type of request.

 

You cannot easily use existing .NET code if you do not know the basics of .NET and the way to use it with AutoCAD (you can start reading this topic).

 

In your case:

  1. Start a new class library project in Visual Studio 2017 (or upper)
  2. Target the .NET Framework 4.7
  3. Add accoremgd.dll, acdbmgd.dll and acmgd.dll references from 'ObjectARX 2020\inc' folder
  4. Set the Copy Local property of these reference to False
  5. Add acsmcomponents23.tlb reference from 'ObjectARX 2020\inc-x64' folder
  6. Paste the original code in the class crated by Visual Studio
  7. Replace: 'using Comp = ACSMCOMPONENTS19lib' with 'using Comp = ACSMCOMPONENTS23lib'

That's all, the proct would compile without error.


 

In your case:

  1. Start a new class library project in Visual Studio 2017 (or upper)
    I used C# Autodesk Wizard
  2. Target the .NET Framework 4.7
    Automatically was target Target the .NET Framework 4.7.1
  3. Add accoremgd.dll, acdbmgd.dll and acmgd.dll references from 'ObjectARX 2020\inc' folder
    Automatically was added those references for Autodesk Wizard.
  4. Set the Copy Local property of these reference to False
    All references were setting in FALSE
  5. Add acsmcomponents23.tlb reference from 'ObjectARX 2020\inc-x64' folder
    I need to add AcSmComponents23, according to kdub in this post: 
    http://www.theswamp.org/index.php?topic=55116.msg594173#msg594173

    image.png



  6. Paste the original code in the class created by Visual Studio
    there was 2 created for AUTODESK Wizard with names "plug-in.cs" and "myCommands.cs".I deleted one and pasted my code. 
  7. Replace: 'using Comp = ACSMCOMPONENTS19lib' with 'using Comp = ACSMCOMPONENTS23lib'
    I already replaced inside the code.

    // (C) Copyright 2019 by  
    //
    using System;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.EditorInput;
    
    /*
     * 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.ACSMCOMPONENTS23Lib.dll
     */
    
    
    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 = ACSMCOMPONENTS23Lib;
    
    [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)
            {
                Array array = null;
                component.GetDirectlyOwnedObjects(out 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)
                        {
                            Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;
    
                            String cur_str_value = sheet.GetNumber();
                            Int32 int_value = 0;
                            Boolean is_int32 = Int32.TryParse(cur_str_value, out 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)
                        {
                            Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
                        }
                        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
        }
    }
    
    




 

 

Message 4 of 12
jtm2020hyo
in reply to: _gile

Here 2 versions of the same developer, maybe there is the issue:

 

http://www.theswamp.org/index.php?topic=45672.msg508180#msg508180

...and here another version (a 3rd ) of the same code with same commands:

https://sites.google.com/site/acadhowtodo/net/sheet-set/update-sheets-numbers

...So, What can I do now?

Message 5 of 12
jtm2020hyo
in reply to: _gile

I tried to fix this problem for my self, I compared that 3 versions of the same code and obtain this:

 

/*
 * 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.ACSMCOMPONENTS23Lib.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 = ACSMCOMPONENTS23Lib;

[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)
        {
            Array array = null;
            component.GetDirectlyOwnedObjects(out 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)
                    {
                        Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;

                        String cur_str_value = sheet.GetNumber();
                        Int32 int_value = 0;
                        Boolean is_int32 = Int32.TryParse(cur_str_value, out 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)
                    {
                        Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
                    }
                    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
    }
}

this code has minimal modifications, but now I have 4 "messages" in VS 2017:

 

Severity	Code	Description	Project	File	Line	Suppression State
Message	IDE0018	Variable declaration can be inlined	ss-renumber2	C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs	127	Active
Message	IDE0018	Variable declaration can be inlined	ss-renumber2	C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs	110	Active
Message	IDE0020	Use pattern matching	ss-renumber2	C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs	124	Active
Message	IDE0020	Use pattern matching	ss-renumber2	C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs	144	Active

after that VS solved such message automatically, obtaining this code: 

 

/*
 * 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.ACSMCOMPONENTS23Lib.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 = ACSMCOMPONENTS23Lib;

[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
    }
}

When I tried to "Start Debugging", Just opened Autocad 2020 but typing the commands "SS-RENUMBER-ALL" and "SS-RENUMBER-ALL-BASES-OF-FIRST" do nothing, and does not show such command load...

 

...But When I press "BUILD" and use NETLOAD for the ".DLL" file, then load without problems and typing commands I have a response:

 

image.png

 

"SS-RENUMBER-ALL" and "SS-RENUMBER-ALL-BASES-OF-FIRST" simply does not works, So, What should I do now?

 

 

 

 

Message 6 of 12
jtm2020hyo
in reply to: _gile

A leave a link with my project:

https://send.firefox.com/download/28c7b36ab4b24481/#o45gijGnBHQydo8JsCeENQ

 

Message 7 of 12
_gile
in reply to: jtm2020hyo


@jtm2020hyo wrote:

 

"SS-RENUMBER-ALL" and "SS-RENUMBER-ALL-BASES-OF-FIRST" simply does not works, So, What should I do now?


I really do not know.

What do you mean with "simply does not work"?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 12
fieldguy
in reply to: jtm2020hyo

>>When I tried to "Start Debugging", Just opened Autocad 2020 but typing the commands "SS-RENUMBER-ALL"

when autocad starts from vs debug you have to use netload.  autocad does not know about your program yet

Message 9 of 12
jtm2020hyo
in reply to: _gile


@_gile wrote:

@jtm2020hyo wrote:

 

"SS-RENUMBER-ALL" and "SS-RENUMBER-ALL-BASES-OF-FIRST" simply does not works, So, What should I do now?


I really do not know.

What do you mean with "simply does not work"?


I really do not know.

1 If possible check my project inside the .zip might be easy solver this problem.
2 If possible share the solved code with a .zip will be very appreciated. 

 

 

What do you mean with "simply does not work"?


3 I mean both commands do nothing, does not renumber some sheet as say their description. So, what it's wrong now?

Message 10 of 12
jtm2020hyo
in reply to: fieldguy

OMG, this works. Smiley Surprised

 

example:

image.png

 

example using command "SS-renumber-all-bases-of-first"

 

image.png

 

example using command "SS-renumber-all"

 

image.png

 

Thanks everyone

 

PD: autodesk does not let me attach mi .DLL file. so here I leave a LInk, search for "ss-renumber2.dll":


http://www.theswamp.org/index.php?topic=55116.new#new

Message 11 of 12
_gile
in reply to: jtm2020hyo


@jtm2020hyo wrote:
1 If possible check my project inside the .zip might be easy solver this problem.wrong now?

Insted of a solution that anyone should be able to build from some code, you should provide a file on wich the code "does not work".

 


@jtm2020hyo wrote:
2 If possible share the solved code with a .zip will be very appreciated. 

if you're looking for an 'out of the box' solution, you should try to contact the author (Andrey Bushman).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 12 of 12
jtm2020hyo
in reply to: _gile


@_gile wrote:

@jtm2020hyo wrote:
1 If possible check my project inside the .zip might be easy solver this problem.wrong now?

Insted of a solution that anyone should be able to build from some code, you should provide a file on wich the code "does not work".

 


@jtm2020hyo wrote:
2 If possible share the solved code with a .zip will be very appreciated. 

if you're looking for an 'out of the box' solution, you should try to contact the author (Andrey Bushman).


/*
 * 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.ACSMCOMPONENTS23Lib.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 = ACSMCOMPONENTS23Lib;

[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
    }
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost