我需要更新一个旧的2014 VB.net,将图纸集重新编号为Autocad 2020。
我使用的是VS 2017和VS 2019。
原始帖子:
http://www.theswamp.org/index.php?topic=45672.msg508180#msg508180
这是我的版本:
- // (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
- ///
- /// 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;
|