28/10/2015
Установка и очистка признака модификации документа в .NET
Для установки и очистки признака модифицированности документа можно воспользоваться недокументированной функцией acdbSetDbMod, которая экспортируется из acdbNN.dll, где NN зависит от версии AutoCAD. Пример использования этой функции:
Код - C#: [Выделить]
- using System;
- using System.Runtime.InteropServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- [assembly: CommandClass(typeof(Rivilis.SetDbMod))]
- namespace Rivilis
- {
- public class SetDbMod
- {
- #region acdbSetDbmod
- [DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod17x86(IntPtr db, Int32 newDbMod);
- [DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod17x64(IntPtr db, Int32 newDbMod);
- [DllImport("acdb18.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod18x86(IntPtr db, Int32 newDbMod);
- [DllImport("acdb18.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod18x64(IntPtr db, Int32 newDbMod);
- [DllImport("acdb19.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod19x86(IntPtr db, Int32 newDbMod);
- [DllImport("acdb19.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod19x64(IntPtr db, Int32 newDbMod);
- [DllImport("acdb20.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod20x86(IntPtr db, Int32 newDbMod);
- [DllImport("acdb20.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod20x64(IntPtr db, Int32 newDbMod);
- [DllImport("acdb21.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod21x86(IntPtr db, Int32 newDbMod);
- [DllImport("acdb21.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbSetDbmod@@YAJPEAVAcDbDatabase@@J@Z")]
- private static extern Int32 acdbSetDbmod21x64(IntPtr db, Int32 newDbMod);
- public static Int32 acdbSetDbmod(ref Database db, Int32 newDbMod)
- {
- if (IntPtr.Size == 4)
- switch (Autodesk.AutoCAD.ApplicationServices.Application.Version.Major) {
- case 17: return acdbSetDbmod17x86(db.UnmanagedObject, newDbMod);
- case 18: return acdbSetDbmod18x86(db.UnmanagedObject, newDbMod);
- case 19: return acdbSetDbmod19x86(db.UnmanagedObject, newDbMod);
- case 20: return acdbSetDbmod20x86(db.UnmanagedObject, newDbMod);
- case 21: return acdbSetDbmod21x86(db.UnmanagedObject, newDbMod);
- default: return (Int32)ErrorStatus.NotImplementedYet;
- }
- else
- switch (Autodesk.AutoCAD.ApplicationServices.Application.Version.Major) {
- case 17: return acdbSetDbmod17x64(db.UnmanagedObject, newDbMod);
- case 18: return acdbSetDbmod18x64(db.UnmanagedObject, newDbMod);
- case 19: return acdbSetDbmod19x64(db.UnmanagedObject, newDbMod);
- case 20: return acdbSetDbmod20x64(db.UnmanagedObject, newDbMod);
- case 21: return acdbSetDbmod21x64(db.UnmanagedObject, newDbMod);
- default: return (Int32)ErrorStatus.NotImplementedYet;
- }
- }
- #endregion
- //---------------------------------------------
- // Установка DBMOD для активного документа
- //---------------------------------------------
- [CommandMethod("SetCurDbMod")]
- static public void SetCurDbMod()
- {
- Database db = Application.DocumentManager.MdiActiveDocument.Database;
- acdbSetDbmod(ref db, 1);
- }
- //---------------------------------------------
- // Очистка DBMOD для активного документа
- //---------------------------------------------
- [CommandMethod("ClearCurDbMod")]
- static public void ClearCurDbMod()
- {
- Database db = Application.DocumentManager.MdiActiveDocument.Database;
- acdbSetDbmod(ref db, 0);
- }
- //---------------------------------------------
- // Очистка DBMOD для всех открытых документов
- //---------------------------------------------
- [CommandMethod("ClearAllDbMod")]
- static public void ClearAllDbMod()
- {
- foreach (Document doc in Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager) {
- Database db = doc.Database;
- acdbSetDbmod(ref db, 0);
- }
- }
- };
- }
Автор: Александр Ривилис
Отредактировано 28.10.2015 в 00:07:33
Обсуждение: http://adn-cis.org/forum/index.php?topic=3148
Опубликовано 28.10.2015Отредактировано 28.10.2015 в 00:07:33