ADN Open CIS
Сообщество программистов Autodesk в СНГ

28/10/2015

Установка и очистка признака модификации документа в .NET

Для установки и очистки признака модифицированности документа можно воспользоваться недокументированной функцией acdbSetDbMod, которая экспортируется из acdbNN.dll, где NN зависит от версии AutoCAD. Пример использования этой функции:

Код - C#: [Выделить]
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Autodesk.AutoCAD.Runtime;
  4. using Autodesk.AutoCAD.ApplicationServices;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. [assembly: CommandClass(typeof(Rivilis.SetDbMod))]
  7. namespace Rivilis
  8. {
  9.   public class SetDbMod
  10.   {
  11.     #region acdbSetDbmod
  12.     [DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
  13.     private static extern Int32 acdbSetDbmod17x86(IntPtr db, Int32 newDbMod);
  14.     [DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
  15.     private static extern Int32 acdbSetDbmod17x64(IntPtr db, Int32 newDbMod);
  16.     [DllImport("acdb18.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
  17.     private static extern Int32 acdbSetDbmod18x86(IntPtr db, Int32 newDbMod);
  18.     [DllImport("acdb18.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
  19.     private static extern Int32 acdbSetDbmod18x64(IntPtr db, Int32 newDbMod);
  20.     [DllImport("acdb19.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
  21.     private static extern Int32 acdbSetDbmod19x86(IntPtr db, Int32 newDbMod);
  22.     [DllImport("acdb19.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
  23.     private static extern Int32 acdbSetDbmod19x64(IntPtr db, Int32 newDbMod);
  24.     [DllImport("acdb20.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
  25.     private static extern Int32 acdbSetDbmod20x86(IntPtr db, Int32 newDbMod);
  26.     [DllImport("acdb20.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
  27.     private static extern Int32 acdbSetDbmod20x64(IntPtr db, Int32 newDbMod);
  28.     [DllImport("acdb21.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
  29.     private static extern Int32 acdbSetDbmod21x86(IntPtr db, Int32 newDbMod);
  30.     [DllImport("acdb21.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
  31.     private static extern Int32 acdbSetDbmod21x64(IntPtr db, Int32 newDbMod);
  32.  
  33.     public static Int32 acdbSetDbmod(ref Database db, Int32 newDbMod)
  34.     {
  35.       if (IntPtr.Size == 4)
  36.       switch (Autodesk.AutoCAD.ApplicationServices.Application.Version.Major) {
  37.         case 17: return acdbSetDbmod17x86(db.UnmanagedObject, newDbMod);
  38.         case 18: return acdbSetDbmod18x86(db.UnmanagedObject, newDbMod);
  39.         case 19: return acdbSetDbmod19x86(db.UnmanagedObject, newDbMod);
  40.         case 20: return acdbSetDbmod20x86(db.UnmanagedObject, newDbMod);
  41.         case 21: return acdbSetDbmod21x86(db.UnmanagedObject, newDbMod);
  42.         default: return (Int32)ErrorStatus.NotImplementedYet;
  43.       }
  44.       else
  45.         switch (Autodesk.AutoCAD.ApplicationServices.Application.Version.Major) {
  46.           case 17: return acdbSetDbmod17x64(db.UnmanagedObject, newDbMod);
  47.           case 18: return acdbSetDbmod18x64(db.UnmanagedObject, newDbMod);
  48.           case 19: return acdbSetDbmod19x64(db.UnmanagedObject, newDbMod);
  49.           case 20: return acdbSetDbmod20x64(db.UnmanagedObject, newDbMod);
  50.           case 21: return acdbSetDbmod21x64(db.UnmanagedObject, newDbMod);
  51.           default: return (Int32)ErrorStatus.NotImplementedYet;
  52.         }
  53.     }
  54.     #endregion
  55.     //---------------------------------------------
  56.     // Установка DBMOD для активного документа
  57.     //---------------------------------------------
  58.     [CommandMethod("SetCurDbMod")]
  59.     static public void SetCurDbMod()
  60.     {
  61.       Database db = Application.DocumentManager.MdiActiveDocument.Database;
  62.       acdbSetDbmod(ref db, 1);
  63.     }
  64.  
  65.     //---------------------------------------------
  66.     // Очистка DBMOD для активного документа
  67.     //---------------------------------------------
  68.     [CommandMethod("ClearCurDbMod")]
  69.     static public void ClearCurDbMod()
  70.     {
  71.       Database db = Application.DocumentManager.MdiActiveDocument.Database;
  72.       acdbSetDbmod(ref db, 0);
  73.     }
  74.     //---------------------------------------------
  75.     // Очистка DBMOD для всех открытых документов
  76.     //---------------------------------------------
  77.     [CommandMethod("ClearAllDbMod")]
  78.     static public void ClearAllDbMod()
  79.     {
  80.       foreach (Document doc in Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager) {
  81.         Database db = doc.Database;
  82.         acdbSetDbmod(ref db, 0);
  83.       }
  84.     }
  85.   };
  86. }

Автор: Александр Ривилис

Обсуждение: http://adn-cis.org/forum/index.php?topic=3148

Опубликовано 28.10.2015
Отредактировано 28.10.2015 в 01:07:33