Author Topic: How to update a 2014 C#.NET to 2020 version?  (Read 8863 times)

0 Members and 1 Guest are viewing this topic.

jtm2020hyo

  • Newt
  • Posts: 198
How to update a 2014 C#.NET to 2020 version?
« on: April 20, 2019, 09:48:45 PM »
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



here my version:

Code: [Select]
// (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;

///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
///* 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
    }
}





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




« Last Edit: April 20, 2019, 10:23:34 PM by jtm2018hyo »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: How to update a 2014 VB.NET to 2020 version?
« Reply #1 on: April 20, 2019, 10:14:46 PM »

Quote
>>> but I always have errors.

What are the errors .. exactly ?

Do you know what changes you made and why you made the changes you made ?
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 VB.NET to 2020 version?
« Reply #2 on: April 20, 2019, 10:27:40 PM »

Quote
>>> but I always have errors.

What are the errors .. exactly ?

Do you know what changes you made and why you made the changes you made ?


I changed "ACSMCOMPONENTS19Lib" for "ACSMCOMPONENTS23Lib" because was recommended in another post.

accord to the post needed to change it to use this old .NET in AutoCAD 2020.

POST:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/add-the-reference-quot-interop-acsmcomponents19lib-dll-quot/m-p/8743453/highlight/true#M384092

Code: [Select]
my questions:
3 Where can I get the ObjectARX 2020 SDK?
4 Should I change all texts "Interop.ACSMCOMPONENTS19Lib.dll" for "Interop.ACSMCOMPONENTS23Lib.dll" inside the code?

his answer:
3. here.
4. Yes for sure.



ERRORS:
Code: [Select]
Severity Code Description Project File Line Suppression State
Warning There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Interop.ACSMCOMPONENTS23Lib, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. AutoCAD CSharp plug-in2
Error CS0246 The type or namespace name 'ACSMCOMPONENTS23Lib' could not be found (are you missing a using directive or an assembly reference?) AutoCAD CSharp plug-in2 C:\Users\JuanJ\source\repos\AutoCAD CSharp plug-in2\AutoCAD CSharp plug-in2\Class1.cs 37 Active
Error CS0246 The type or namespace name 'ACSMCOMPONENTS23Lib' could not be found (are you missing a using directive or an assembly reference?) AutoCAD CSharp plug-in2 C:\Users\JuanJ\source\repos\AutoCAD CSharp plug-in2\AutoCAD CSharp plug-in2\Class1.cs 37 Active
Error CS0579 Duplicate 'Rtm.ExtensionApplication' attribute AutoCAD CSharp plug-in2 C:\Users\JuanJ\source\repos\AutoCAD CSharp plug-in2\AutoCAD CSharp plug-in2\Class1.cs 39 Active

I already created the reference "ACSMCOMPONENTS23Lib" with:

Code: [Select]
C:\Windows\system32>"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:"Interop.ACSMCOMPONENTS23Lib.dll"  /namespace:AcSm  /machine:x64
Microsoft (R) .NET Framework Type Library to Assembly Converter 4.8.3761.0                                                                                     Copyright (C) Microsoft Corporation.  All rights reserved.
TlbImp : warning TI3015 : At least one of the arguments for 'AcSm.IAcSmFiler.ReadRawData' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
TlbImp : warning TI3015 : At least one of the arguments for 'AcSm.IAcSmFiler.ReadBytes' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
TlbImp : warning TI3019 : Interface 'IAcadShadowDisplay' is marked as [dual], but does not derive from IDispatch. It will be converted as an IUnknown-derived interface. 
TlbImp : warning TI3015 : At least one of the arguments for 'AcSm.IAcSmPersistProxy.GetRawData' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.                                                                               
TlbImp : warning TI3015 : At least one of the arguments for 'AcSm.AcSmDSTFilerClass.ReadRawData' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.                                                                               
TlbImp : warning TI3015 : At least one of the arguments for 'AcSm.AcSmDSTFilerClass.ReadBytes' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.                                                                                 
TlbImp : warning TI3015 : At least one of the arguments for 'AcSm.AcSmPersistProxyClass.GetRawData' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.                                                                           
TlbImp : Type library imported to C:\Windows\system32\Interop.ACSMCOMPONENTS23Lib.dll     

« Last Edit: April 20, 2019, 10:38:58 PM by jtm2018hyo »

jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 VB.NET to 2020 version?
« Reply #3 on: April 20, 2019, 10:41:50 PM »

Quote
>>> but I always have errors.

What are the errors .. exactly ?

Do you know what changes you made and why you made the changes you made ?

I used a command suggested in this post:

https://forums.autodesk.com/t5/objectarx/objectarx-for-autocad-2013/m-p/8743364#M38516

Code: [Select]
tlbimp acsmcomponents23.tlb /out:Interop.ACSMCOMPONENTS23Lib.dll /namespace:AcSm /machine:x64

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #4 on: April 20, 2019, 11:08:51 PM »

I used a command suggested in this post:

https://forums.autodesk.com/t5/objectarx/objectarx-for-autocad-2013/m-p/8743364#M38516

Code: [Select]
tlbimp acsmcomponents23.tlb /out:Interop.ACSMCOMPONENTS23Lib.dll /namespace:AcSm /machine:x64


I don't know why you needed to do that .. I get this straight out of the box ....

Perhaps you need to ask Alexander ... BUT you did ask him in the ObjectARX Forum and he would have been justified in believing you wanted the functionality for an ARX application.

Does your VS C# References look anything like this ??
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #5 on: April 20, 2019, 11:26:54 PM »

There are several versions of Andrey's code floating around ... without the miriad versions you have been posting recently.
Do you know where you got the version you are using ??

Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #6 on: April 20, 2019, 11:36:57 PM »

I used a command suggested in this post:

https://forums.autodesk.com/t5/objectarx/objectarx-for-autocad-2013/m-p/8743364#M38516

Code: [Select]
tlbimp acsmcomponents23.tlb /out:Interop.ACSMCOMPONENTS23Lib.dll /namespace:AcSm /machine:x64


I don't know why you needed to do that .. I get this straight out of the box ....

Perhaps you need to ask Alexander ... BUT you did ask him in the ObjectARX Forum and he would have been justified in believing you wanted the functionality for an ARX application.

Does your VS C# References look anything like this ??


thanks for your help friend...

I just have one error more:

Code: [Select]
Severity Code Description Project File Line Suppression State
Error CS0579 Duplicate 'Rtm.ExtensionApplication' attribute ss-renumber2 C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\Class1.cs 32 Active

here:

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

I'm not sure what do here.

jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #7 on: April 20, 2019, 11:47:35 PM »

There are several versions of Andrey's code floating around ... without the miriad versions you have been posting recently.
Do you know where you got the version you are using ??

Regards,

... this is the code that I'm, I did not sure if I did the correct changing ACSMCOMPONENTS19Lib for ACSMCOMPONENTS23Lib:

Code: [Select]
///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
///"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:"Interop.ACSMCOMPONENTS23Lib.dll"  /namespace:AcSm  /machine:x64

/*
 * 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
    }
}


jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #8 on: April 21, 2019, 01:40:33 AM »

There are several versions of Andrey's code floating around ... without the miriad versions you have been posting recently.
Do you know where you got the version you are using ??

Regards,

...well I solved the duplicated problem.

but now I build the DLL file but SS-renumber-all and SS-RENUMBER-ALL-BASES-OF-FIRST does not work.

What can I do?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #9 on: April 21, 2019, 04:20:23 AM »
I replied there. :whistling:
Speaking English as a French Frog

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #10 on: April 21, 2019, 04:52:50 AM »

...well I solved the duplicated problem.

How did you solve the issue ?


 
                                             
... but now I build the DLL file but SS-renumber-all and SS-RENUMBER-ALL-BASES-OF-FIRST does not work.


So,
Does it compile without error ?

Does it NetLoad into AutoCAD without issue ?

Does each command  appear to run without fault ?

Have you tried stepping through the code in the debugger to check the code flow ?
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #11 on: April 21, 2019, 10:43:41 AM »

...well I solved the duplicated problem.

How did you solve the issue ?


 
                                             
... but now I build the DLL file but SS-renumber-all and SS-RENUMBER-ALL-BASES-OF-FIRST does not work.


So,
Does it compile without error ?

Does it NetLoad into AutoCAD without issue ?

Does each command  appear to run without fault ?

Have you tried stepping through the code in the debugger to check the code flow ?

0 How did you solve the issue?
0 AUTODESK WIZARD automatically creates 2 ".CS", I just left one ".CS", deleted all and pasted all the code.

1 Does it compile without error?
1 YES

2 Does it NetLoad into AutoCAD without issue?
2 YES

3 Does each command appear to run without fault?
3 Do nothing both commands after loading with NETLOAD
3 But load both commands without problems.

4 Have you tried stepping through the code in the debugger to check the code flow?
4 yes, do nothing when debugging
4 Does not load both commands


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

Code: [Select]
http://www.theswamp.org/index.php?topic=45672.msg508180#msg508180

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

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

...So, What can I do now?



« Last Edit: April 21, 2019, 11:17:14 AM by jtm2018hyo »

jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #12 on: April 21, 2019, 11:52:49 AM »

...well I solved the duplicated problem.

How did you solve the issue ?


 
                                             
... but now I build the DLL file but SS-renumber-all and SS-RENUMBER-ALL-BASES-OF-FIRST does not work.


So,
Does it compile without error ?

Does it NetLoad into AutoCAD without issue ?

Does each command  appear to run without fault ?

Have you tried stepping through the code in the debugger to check the code flow?


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

Code: [Select]
/*
 * 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:

Code: [Select]
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

I'm not sure if this is the correct way but maybe I saved a bit of your time.

jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #13 on: April 21, 2019, 12:12:21 PM »
after that VS solved such message automatically, obtaining this code:


Code: [Select]
/*
 * 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:




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

















jtm2020hyo

  • Newt
  • Posts: 198
Re: How to update a 2014 C#.NET to 2020 version?
« Reply #14 on: April 21, 2019, 12:17:46 PM »
A leave a link with my project:

Code: [Select]
https://send.firefox.com/download/28c7b36ab4b24481/#o45gijGnBHQydo8JsCeENQ