乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 199|回复: 10

如何更新一个2014的C#?NET到2020版?

[复制链接]

68

主题

179

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
451
发表于 2019-4-20 21:48:45 | 显示全部楼层 |阅读模式
我需要更新一个旧的2014 VB.net,将图纸集重新编号为Autocad 2020。
我使用的是VS 2017和VS 2019。
原始帖子:
http://www.theswamp.org/index.php?topic=45672.msg508180#msg508180
这是我的版本:
  1. // (C) Copyright 2019 by  
  2. //
  3. //using System;
  4. using Autodesk.AutoCAD.Runtime;
  5. using Autodesk.AutoCAD.ApplicationServices;
  6. using Autodesk.AutoCAD.DatabaseServices;
  7. using Autodesk.AutoCAD.Geometry;
  8. using Autodesk.AutoCAD.EditorInput;
  9. ///tlbimp acsmcomponents19.tlb /out:Interop.ACSMCOMPONENTS19Lib.dll  /namespace:AcSm  /machine:x64
  10. ///tlbimp acsmcomponents23.tlb /out:Interop.ACSMCOMPONENTS23Lib.dll  /namespace:AcSm  /machine:x64
  11. ///"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
  12. ///*
  13. ///* SheetSetTools. © Andrey Bushman, 2013
  14. ///* AutoCAD 2014 x64 Enu
  15. ///*
  16. ///* COMMANDS:
  17. ///* SS-RENUMBER-ALL - Update the numeration for all sheets in the all opened sheet sets:
  18. ///* numbering of each subgroup shall begin with 1.
  19. ///*
  20. ///* SS-RENUMBER-ALL-BASES-OF-FIRST - Update the numeration: to continue numbering on the
  21. ///* basis of the first element in the each subset (in the all opened sheet sets).
  22. ///*
  23. ///* AutoCAD references:
  24. ///* AcCoreMgd.dll
  25. ///* AcDbMgd.dll
  26. ///* AcMgd.dll
  27. ///* Interop.ACSMCOMPONENTS23Lib.dll
  28. ///*/
  29. using System;
  30. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  31. using App = Autodesk.AutoCAD.ApplicationServices;
  32. using Db = Autodesk.AutoCAD.DatabaseServices;
  33. using Ed = Autodesk.AutoCAD.EditorInput;
  34. using Rtm = Autodesk.AutoCAD.Runtime;
  35. using Comp = ACSMCOMPONENTS23Lib;
  36. [assembly: Rtm.ExtensionApplication(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]
  37. [assembly: Rtm.CommandClass(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]
  38. namespace Bushman.AutoCAD.SheetSetTools
  39. {
  40.     public class SheetSetCommands : Rtm.IExtensionApplication
  41.     {
  42.         const String ns = "bush"; // namespace
  43.         ///
  44.         /// Update the numeration for all sheets in the all opened sheet sets: numbering of
  45.         /// each subgroup shall begin with 1.
  46.         ///
  47.         [Rtm.CommandMethod(ns, "ss-renumber-all", Rtm.CommandFlags.Modal)]
  48.         public void Renumber_All()
  49.         {
  50.             Renumber();
  51.         }
  52.         ///
  53.         /// Update the numeration: to continue numbering on the basis of the first element
  54.         /// in the each subset (in the all opened sheet sets).
  55.         ///
  56.         [Rtm.CommandMethod(ns, "ss-renumber-all-bases-of-first", Rtm.CommandFlags.Modal)]
  57.         public void Renumber_all_bases_of_first()
  58.         {
  59.             Renumber(true);
  60.         }
  61.         ///
  62.         /// To update numbering of all sheets in the all opened sheet sets.
  63.         ///
  64.         /// True - to continue numbering on the basis
  65.         /// of the first element in the each subset (in the all opened sheet sets);
  66.         /// False - Numbering of each subgroup shall begin with 1 (in the all opened
  67.         /// sheet sets).
  68.         void Renumber(Boolean continue_numbering = false)
  69.         {
  70.             App.Document doc = cad.DocumentManager.MdiActiveDocument;
  71.             Db.Database db = doc.Database;
  72.             Ed.Editor ed = doc.Editor;
  73.             Comp.AcSmSheetSetMgr mng = new Comp.AcSmSheetSetMgr();
  74.             Comp.IAcSmEnumDatabase enumerator = mng.GetDatabaseEnumerator();
  75.             enumerator.Reset();
  76.             Comp.AcSmDatabase smDb = null;
  77.             while ((smDb = enumerator.Next()) != null)
  78.             {
  79.                 smDb.LockDb(db);
  80.                 String fname = smDb.GetFileName();
  81.                 Comp.AcSmSheetSet sheetset = smDb.GetSheetSet();
  82.                 String name = sheetset.GetName();
  83.                 String descr = sheetset.GetDesc();
  84.                 ed.WriteMessage("\nSheet Set name: {0}\n", name);
  85.                 Int32 ren_count = 0; // count of renamed sheets.
  86.                 Comp.IAcSmEnumComponent encomp = sheetset.GetSheetEnumerator();
  87.                 encomp.Reset();
  88.                 Comp.IAcSmComponent component = null;
  89.                 while ((component = encomp.Next()) != null)
  90.                 {
  91.                     ProcessElement(ed, component, ref ren_count, continue_numbering);
  92.                 }
  93.                 encomp.Reset();
  94.                 smDb.UnlockDb(db, true);
  95.                 ed.WriteMessage("Renumbered sheets count: {0}\n", ren_count);
  96.             }
  97.             enumerator.Reset();
  98.         }
  99.         ///
  100.         ///  Recursive processing of the elements: change the sheet's number.
  101.         ///
  102.         /// An Editor for the output.
  103.         /// Component of Sheet Set.
  104.         /// The count of renumbered sheets in the sheet set.
  105.         /// True - to continue numbering on the basis
  106.         /// of the first element in the each subset (in the all opened sheet sets);
  107.         /// False - Numbering of each subgroup shall begin with 1 (in the all opened
  108.         /// sheet sets).
  109.         void ProcessElement(Ed.Editor ed, Comp.IAcSmComponent component,
  110.             ref Int32 ren_count, Boolean continue_numbering)
  111.         {
  112.             Array array = null;
  113.             component.GetDirectlyOwnedObjects(out array);
  114.             if (array != null)
  115.             {
  116.                 Int32 sheet_number = 1;
  117.                 Boolean basis_of_first = continue_numbering;
  118.                 foreach (var item in array)
  119.                 {
  120.                     if (item is Comp.IAcSmSubset)
  121.                     {
  122.                         ProcessElement(ed, (Comp.IAcSmSubset)item, ref ren_count, continue_numbering);
  123.                     }
  124.                     else if (item is Comp.IAcSmSheet)
  125.                     {
  126.                         Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;
  127.                         String cur_str_value = sheet.GetNumber();
  128.                         Int32 int_value = 0;
  129.                         Boolean is_int32 = Int32.TryParse(cur_str_value, out int_value);
  130.                         if (!is_int32 || (!basis_of_first && int_value != sheet_number))
  131.                         {
  132.                             sheet.SetNumber(sheet_number.ToString());
  133.                             ++ren_count;
  134.                         }
  135.                         else if (basis_of_first)
  136.                         {
  137.                             sheet_number = int_value;
  138.                         }
  139.                         ++sheet_number;
  140.                         basis_of_first = false;
  141.                     }
  142.                     else if (item is Comp.IAcSmPersist)
  143.                     {
  144.                         Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
  145.                     }
  146.                     else
  147.                     {
  148.                         ed.WriteMessage("Unknown object: {0}", item.GetType().ToString());
  149.                     }
  150.                 }
  151.             }
  152.         }
  153.         #region IExtensionApplication Members
  154.         public void Initialize()
  155.         {
  156.             App.Document doc = cad.DocumentManager.MdiActiveDocument;
  157.             Ed.Editor ed = doc.Editor;
  158.             ed.WriteMessage("\nSheetSetTools. © Andrey Bushman, 2013\n\n");
  159.         }
  160.         public void Terminate()
  161.         {
  162.             // Empty body.
  163.         }
  164.         #endregion
  165.     }
  166. }

那么,我该怎么做呢?(如有可能,请逐项解释)

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

57

主题

559

帖子

13

银币

中流砥柱

Rank: 25

铜币
786
发表于 2019-4-20 22:14:46 | 显示全部楼层

究竟有哪些错误?
您知道您进行了哪些更改以及为什么进行了更改吗?
回复

使用道具 举报

68

主题

179

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
451
发表于 2019-4-20 22:27:40 | 显示全部楼层

有哪些错误..确实如此。
您知道自己做了哪些更改以及为什么要做这些更改吗?

我将“ACSMCOMPONENTS19Lib”改为“ACSMCOMPONENTS23Lib”,因为在另一篇文章中推荐了。
根据岗位需要换成用这个旧的。NET在AutoCAD 2020中的应用。
POST:
https://forums . Autodesk . com/t5/visual-lisp-AutoLISP-and-general/add-the-reference-quot-interop-acsmcomponents 19 lib-dll-quot/m-p/8743453/highlight/true # m 384092

  1. my questions:
  2. 3 Where can I get the ObjectARX 2020 SDK?
  3. 4 Should I change all texts "Interop.ACSMCOMPONENTS19Lib.dll" for "Interop.ACSMCOMPONENTS23Lib.dll" inside the code?
  4. his answer:
  5. 3. here.
  6. 4. Yes for sure.

错误代码2]
我已经用
  1. 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
  2. Microsoft (R) .NET Framework Type Library to Assembly Converter 4.8.3761.0                                                                                     Copyright (C) Microsoft Corporation.  All rights reserved.
  3. 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.
  4. 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.
  5. TlbImp : warning TI3019 : Interface 'IAcadShadowDisplay' is marked as [dual], but does not derive from IDispatch. It will be converted as an IUnknown-derived interface.  
  6. 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.                                                                                
  7. 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.                                                                              
  8. 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.                                                                                 
  9. 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.                                                                           
  10. TlbImp : Type library imported to C:\Windows\system32\Interop.ACSMCOMPONENTS23Lib.dll     

回复

使用道具 举报

68

主题

179

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
451
发表于 2019-4-20 22:41:50 | 显示全部楼层

错误是什么...到底?
你知道你做了什么更改以及为什么要做这些更改吗?

我使用了这篇文章中建议的命令:
https://forums.autodesk.com/t5/objectarx/objectarx-for-autocad-2013/m-p/8743364#M38516
  1. tlbimp acsmcomponents23.tlb /out:Interop.ACSMCOMPONENTS23Lib.dll /namespace:AcSm /machine:x64

回复

使用道具 举报

57

主题

559

帖子

13

银币

中流砥柱

Rank: 25

铜币
786
发表于 2019-4-20 23:08:51 | 显示全部楼层
我不知道
你为什么需要这样做..我把这个直接从盒子里拿出来....
也许你需要问亚历山大...但是你确实在ObjectARX论坛上问过他,他有理由相信你想要ARX应用程序的功能。
您的 VS C# 引用是否看起来像这样??
回复

使用道具 举报

57

主题

559

帖子

13

银币

中流砥柱

Rank: 25

铜币
786
发表于 2019-4-20 23:26:54 | 显示全部楼层

安德烈的代码有几个版本…没有你最近发布的miriad版本
你知道你从哪里得到你正在使用的版本吗
回复

使用道具 举报

68

主题

179

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
451
发表于 2019-4-20 23:36:57 | 显示全部楼层

我不知道你为什么要这么做...我直接开箱即用......
也许你需要问亚历山大...但是你确实在ObjectARX论坛上问过他,他有理由相信你想要ARX应用程序的功能。
您的VS C#引用看起来像这样吗??

感谢您的帮助朋友...
我还有一个错误:
  1. Severity        Code        Description        Project        File        Line        Suppression State
  2. Error        CS0579        Duplicate 'Rtm.ExtensionApplication' attribute        ss-renumber2        C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\Class1.cs        32        Active

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

我不确定在这里做什么。
回复

使用道具 举报

68

主题

179

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
451
发表于 2019-4-20 23:47:35 | 显示全部楼层

…这是我正在编写的代码,我不确定是否正确地将ACSMCOMPONENTS19Lib更改为ACSMCompoonets23lib:
  1. ///tlbimp acsmcomponents19.tlb /out:Interop.ACSMCOMPONENTS19Lib.dll  /namespace:AcSm  /machine:x64
  2. ///tlbimp acsmcomponents23.tlb /out:Interop.ACSMCOMPONENTS23Lib.dll  /namespace:AcSm  /machine:x64
  3. ///"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
  4. ///"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
  5. /*
  6. * SheetSetTools. © Andrey Bushman, 2013
  7. * AutoCAD 2014 x64 Enu
  8. *
  9. * COMMANDS:
  10. * SS-RENUMBER-ALL - Update the numeration for all sheets in the all opened sheet sets:
  11. * numbering of each subgroup shall begin with 1.
  12. *
  13. * SS-RENUMBER-ALL-BASES-OF-FIRST - Update the numeration: to continue numbering on the
  14. * basis of the first element in the each subset (in the all opened sheet sets).
  15. *
  16. * AutoCAD references:
  17. * AcCoreMgd.dll
  18. * AcDbMgd.dll
  19. * AcMgd.dll
  20. * Interop.ACSMCOMPONENTS23Lib.dll
  21. */
  22. using System;
  23. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  24. using App = Autodesk.AutoCAD.ApplicationServices;
  25. using Db = Autodesk.AutoCAD.DatabaseServices;
  26. using Ed = Autodesk.AutoCAD.EditorInput;
  27. using Rtm = Autodesk.AutoCAD.Runtime;
  28. using Comp = ACSMCOMPONENTS23Lib;
  29. [assembly: Rtm.ExtensionApplication(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]
  30. [assembly: Rtm.CommandClass(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]
  31. namespace Bushman.AutoCAD.SheetSetTools
  32. {
  33.     public class SheetSetCommands : Rtm.IExtensionApplication
  34.     {
  35.         const String ns = "bush"; // namespace
  36.         ///
  37.         /// Update the numeration for all sheets in the all opened sheet sets: numbering of
  38.         /// each subgroup shall begin with 1.
  39.         ///
  40.         [Rtm.CommandMethod(ns, "ss-renumber-all", Rtm.CommandFlags.Modal)]
  41.         public void Renumber_All()
  42.         {
  43.             Renumber();
  44.         }
  45.         ///
  46.         /// Update the numeration: to continue numbering on the basis of the first element
  47.         /// in the each subset (in the all opened sheet sets).
  48.         ///
  49.         [Rtm.CommandMethod(ns, "ss-renumber-all-bases-of-first", Rtm.CommandFlags.Modal)]
  50.         public void Renumber_all_bases_of_first()
  51.         {
  52.             Renumber(true);
  53.         }
  54.         ///
  55.         /// To update numbering of all sheets in the all opened sheet sets.
  56.         ///
  57.         /// True - to continue numbering on the basis
  58.         /// of the first element in the each subset (in the all opened sheet sets);
  59.         /// False - Numbering of each subgroup shall begin with 1 (in the all opened
  60.         /// sheet sets).
  61.         void Renumber(Boolean continue_numbering = false)
  62.         {
  63.             App.Document doc = cad.DocumentManager.MdiActiveDocument;
  64.             Db.Database db = doc.Database;
  65.             Ed.Editor ed = doc.Editor;
  66.             Comp.AcSmSheetSetMgr mng = new Comp.AcSmSheetSetMgr();
  67.             Comp.IAcSmEnumDatabase enumerator = mng.GetDatabaseEnumerator();
  68.             enumerator.Reset();
  69.             Comp.AcSmDatabase smDb = null;
  70.             while ((smDb = enumerator.Next()) != null)
  71.             {
  72.                 smDb.LockDb(db);
  73.                 String fname = smDb.GetFileName();
  74.                 Comp.AcSmSheetSet sheetset = smDb.GetSheetSet();
  75.                 String name = sheetset.GetName();
  76.                 String descr = sheetset.GetDesc();
  77.                 ed.WriteMessage("\nSheet Set name: {0}\n", name);
  78.                 Int32 ren_count = 0; // count of renamed sheets.
  79.                 Comp.IAcSmEnumComponent encomp = sheetset.GetSheetEnumerator();
  80.                 encomp.Reset();
  81.                 Comp.IAcSmComponent component = null;
  82.                 while ((component = encomp.Next()) != null)
  83.                 {
  84.                     ProcessElement(ed, component, ref ren_count, continue_numbering);
  85.                 }
  86.                 encomp.Reset();
  87.                 smDb.UnlockDb(db, true);
  88.                 ed.WriteMessage("Renumbered sheets count: {0}\n", ren_count);
  89.             }
  90.             enumerator.Reset();
  91.         }
  92.         ///
  93.         ///  Recursive processing of the elements: change the sheet's number.
  94.         ///
  95.         /// An Editor for the output.
  96.         /// Component of Sheet Set.
  97.         /// The count of renumbered sheets in the sheet set.
  98.         /// True - to continue numbering on the basis
  99.         /// of the first element in the each subset (in the all opened sheet sets);
  100.         /// False - Numbering of each subgroup shall begin with 1 (in the all opened
  101.         /// sheet sets).
  102.         void ProcessElement(Ed.Editor ed, Comp.IAcSmComponent component,
  103.             ref Int32 ren_count, Boolean continue_numbering)
  104.         {
  105.             Array array = null;
  106.             component.GetDirectlyOwnedObjects(out array);
  107.             if (array != null)
  108.             {
  109.                 Int32 sheet_number = 1;
  110.                 Boolean basis_of_first = continue_numbering;
  111.                 foreach (var item in array)
  112.                 {
  113.                     if (item is Comp.IAcSmSubset)
  114.                     {
  115.                         ProcessElement(ed, (Comp.IAcSmSubset)item, ref ren_count, continue_numbering);
  116.                     }
  117.                     else if (item is Comp.IAcSmSheet)
  118.                     {
  119.                         Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;
  120.                         String cur_str_value = sheet.GetNumber();
  121.                         Int32 int_value = 0;
  122.                         Boolean is_int32 = Int32.TryParse(cur_str_value, out int_value);
  123.                         if (!is_int32 || (!basis_of_first && int_value != sheet_number))
  124.                         {
  125.                             sheet.SetNumber(sheet_number.ToString());
  126.                             ++ren_count;
  127.                         }
  128.                         else if (basis_of_first)
  129.                         {
  130.                             sheet_number = int_value;
  131.                         }
  132.                         ++sheet_number;
  133.                         basis_of_first = false;
  134.                     }
  135.                     else if (item is Comp.IAcSmPersist)
  136.                     {
  137.                         Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
  138.                     }
  139.                     else
  140.                     {
  141.                         ed.WriteMessage("Unknown object: {0}", item.GetType().ToString());
  142.                     }
  143.                 }
  144.             }
  145.         }
  146.         #region IExtensionApplication Members
  147.         public void Initialize()
  148.         {
  149.             App.Document doc = cad.DocumentManager.MdiActiveDocument;
  150.             Ed.Editor ed = doc.Editor;
  151.             ed.WriteMessage("\nSheetSetTools. © Andrey Bushman, 2013\n\n");
  152.         }
  153.         public void Terminate()
  154.         {
  155.             // Empty body.
  156.         }
  157.         #endregion
  158.     }
  159. }

回复

使用道具 举报

68

主题

179

帖子

6

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
451
发表于 2019-4-21 01:40:33 | 显示全部楼层

…我解决了重复的问题
但是现在我构建了DLL文件,但是SS-renumber-all和SS-reumber-all-BASES-OF-FIRST不起作用
        /// Update the numeration for all sheets in the all opened sheet sets: numbering of
        /// each subgroup shall begin with 1.
        ///
        [Rtm.CommandMethod(ns, "ss-renumber-all", Rtm.CommandFlags.Modal)]
        public void Renumber_All()
        {
            Renumber();
        }
        ///
        /// Update the numeration: to continue numbering on the basis of the first element
        /// in the each subset (in the all opened sheet sets).
        ///
        [Rtm.CommandMethod(ns, "ss-renumber-all-bases-of-first", Rtm.CommandFlags.Modal)]
        public void Renumber_all_bases_of_first()
        {
            Renumber(true);
        }
        ///
        /// To update numbering of all sheets in the all opened sheet sets.
        ///
        /// 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).
        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();
        }
        ///
        ///  Recursive processing of the elements: change the sheet's number.
        ///
        /// An Editor for the output.
        /// Component of Sheet Set.
        /// The count of renumbered sheets in the sheet set.
        /// 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).
        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
    }
}[/code]
这个代码有最小的修改,但现在我在VS 2017中有4个“消息”:
  1. Severity        Code        Description        Project        File        Line        Suppression State
  2. Message        IDE0018        Variable declaration can be inlined        ss-renumber2        C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs        127        Active
  3. Message        IDE0018        Variable declaration can be inlined        ss-renumber2        C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs        110        Active
  4. Message        IDE0020        Use pattern matching        ss-renumber2        C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs        124        Active
  5. Message        IDE0020        Use pattern matching        ss-renumber2        C:\Users\JuanJ\source\repos\ss-renumber-solution2\ss-renumber2\myCommands.cs        144        Active

我不确定这是否是正确的方式,但也许我节省了一点你的时间。
回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2019-4-21 04:20:23 | 显示全部楼层
之后,VS自动解决此类消息,获得此代码:
  1. /*
  2. * SheetSetTools. © Andrey Bushman, 2013
  3. * AutoCAD 2014 x64 Enu
  4. *
  5. * COMMANDS:
  6. * SS-RENUMBER-ALL - Update the numeration for all sheets in the all opened sheet sets:
  7. * numbering of each subgroup shall begin with 1.
  8. *
  9. * SS-RENUMBER-ALL-BASES-OF-FIRST - Update the numeration: to continue numbering on the
  10. * basis of the first element in the each subset (in the all opened sheet sets).
  11. *
  12. * AutoCAD references:
  13. * AcCoreMgd.dll
  14. * AcDbMgd.dll
  15. * AcMgd.dll
  16. * Interop.ACSMCOMPONENTS23Lib.dll
  17. */
  18. using System;
  19. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  20. using App = Autodesk.AutoCAD.ApplicationServices;
  21. using Db = Autodesk.AutoCAD.DatabaseServices;
  22. using Ed = Autodesk.AutoCAD.EditorInput;
  23. using Rtm = Autodesk.AutoCAD.Runtime;
  24. using Comp = ACSMCOMPONENTS23Lib;
  25. [assembly: Rtm.ExtensionApplication(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]
  26. [assembly: Rtm.CommandClass(typeof(Bushman.AutoCAD.SheetSetTools.SheetSetCommands))]
  27. namespace Bushman.AutoCAD.SheetSetTools
  28. {
  29.     public class SheetSetCommands : Rtm.IExtensionApplication
  30.     {
  31.         const String ns = "bush"; // namespace
  32.         ///
  33.         /// Update the numeration for all sheets in the all opened sheet sets: numbering of
  34.         /// each subgroup shall begin with 1.
  35.         ///
  36.         [Rtm.CommandMethod(ns, "ss-renumber-all", Rtm.CommandFlags.Modal)]
  37.         public void Renumber_All()
  38.         {
  39.             Renumber();
  40.         }
  41.         ///
  42.         /// Update the numeration: to continue numbering on the basis of the first element
  43.         /// in the each subset (in the all opened sheet sets).
  44.         ///
  45.         [Rtm.CommandMethod(ns, "ss-renumber-all-bases-of-first", Rtm.CommandFlags.Modal)]
  46.         public void Renumber_all_bases_of_first()
  47.         {
  48.             Renumber(true);
  49.         }
  50.         ///
  51.         /// To update numbering of all sheets in the all opened sheet sets.
  52.         ///
  53.         /// True - to continue numbering on the basis
  54.         /// of the first element in the each subset (in the all opened sheet sets);
  55.         /// False - Numbering of each subgroup shall begin with 1 (in the all opened
  56.         /// sheet sets).
  57.         void Renumber(Boolean continue_numbering = false)
  58.         {
  59.             App.Document doc = cad.DocumentManager.MdiActiveDocument;
  60.             Db.Database db = doc.Database;
  61.             Ed.Editor ed = doc.Editor;
  62.             Comp.AcSmSheetSetMgr mng = new Comp.AcSmSheetSetMgr();
  63.             Comp.IAcSmEnumDatabase enumerator = mng.GetDatabaseEnumerator();
  64.             enumerator.Reset();
  65.             Comp.AcSmDatabase smDb = null;
  66.             while ((smDb = enumerator.Next()) != null)
  67.             {
  68.                 smDb.LockDb(db);
  69.                 String fname = smDb.GetFileName();
  70.                 Comp.AcSmSheetSet sheetset = smDb.GetSheetSet();
  71.                 String name = sheetset.GetName();
  72.                 String descr = sheetset.GetDesc();
  73.                 ed.WriteMessage("\nSheet Set name: {0}\n", name);
  74.                 Int32 ren_count = 0; // count of renamed sheets.
  75.                 Comp.IAcSmEnumComponent encomp = sheetset.GetSheetEnumerator();
  76.                 encomp.Reset();
  77.                 Comp.IAcSmComponent component = null;
  78.                 while ((component = encomp.Next()) != null)
  79.                 {
  80.                     ProcessElement(ed, component, ref ren_count, continue_numbering);
  81.                 }
  82.                 encomp.Reset();
  83.                 smDb.UnlockDb(db, true);
  84.                 ed.WriteMessage("Renumbered sheets count: {0}\n", ren_count);
  85.             }
  86.             enumerator.Reset();
  87.         }
  88.         ///
  89.         ///  Recursive processing of the elements: change the sheet's number.
  90.         ///
  91.         /// An Editor for the output.
  92.         /// Component of Sheet Set.
  93.         /// The count of renumbered sheets in the sheet set.
  94.         /// True - to continue numbering on the basis
  95.         /// of the first element in the each subset (in the all opened sheet sets);
  96.         /// False - Numbering of each subgroup shall begin with 1 (in the all opened
  97.         /// sheet sets).
  98.         void ProcessElement(Ed.Editor ed, Comp.IAcSmComponent component,
  99.             ref Int32 ren_count, Boolean continue_numbering)
  100.         {
  101.             component.GetDirectlyOwnedObjects(out Array array);
  102.             if (array != null)
  103.             {
  104.                 Int32 sheet_number = 1;
  105.                 Boolean basis_of_first = continue_numbering;
  106.                 foreach (var item in array)
  107.                 {
  108.                     if (item is Comp.IAcSmSubset)
  109.                     {
  110.                         ProcessElement(ed, (Comp.IAcSmSubset)item, ref ren_count, continue_numbering);
  111.                     }
  112.                     else if (item is Comp.IAcSmSheet sheet)
  113.                     {
  114.                         String cur_str_value = sheet.GetNumber();
  115.                         Boolean is_int32 = Int32.TryParse(cur_str_value, out int int_value);
  116.                         if (!is_int32 || (!basis_of_first && int_value != sheet_number))
  117.                         {
  118.                             sheet.SetNumber(sheet_number.ToString());
  119.                             ++ren_count;
  120.                         }
  121.                         else if (basis_of_first)
  122.                         {
  123.                             sheet_number = int_value;
  124.                         }
  125.                         ++sheet_number;
  126.                         basis_of_first = false;
  127.                     }
  128.                     else if (item is Comp.IAcSmPersist persist)
  129.                     {
  130.                     }
  131.                     else
  132.                     {
  133.                         ed.WriteMessage("Unknown object: {0}", item.GetType().ToString());
  134.                     }
  135.                 }
  136.             }
  137.         }
  138.         #region IExtensionApplication Members
  139.         public void Initialize()
  140.         {
  141.             App.Document doc = cad.DocumentManager.MdiActiveDocument;
  142.             Ed.Editor ed = doc.Editor;
  143.             ed.WriteMessage("\nSheetSetTools. © Andrey Bushman, 2013\n\n");
  144.         }
  145.         public void Terminate()
  146.         {
  147.             // Empty body.
  148.         }
  149.         #endregion
  150.     }
  151. }

当我尝试“开始调试”时,只是打开了Autocad 2020,但键入命令“SS-RENUMBER-ALL”和“SS-RENUMBER-ALL-BASES-OF-FIRST”却什么也没做,并且不显示这样的命令加载...
...但是当我按下“构建”并使用NETLOAD。DLL "文件,然后加载没有问题和键入命令我有一个响应:


“SS-全部重新编号”和“SS-首先重新编号-所有基数”根本不起作用,那么,我现在该怎么办?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-4 08:51 , Processed in 0.200457 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表