- using System; 
- using System.Reflection; 
- using System.Resources; 
- using System.Globalization; 
- using System.Collections.Generic; 
- using Autodesk.AutoCAD.Runtime; 
- using Autodesk.AutoCAD.ApplicationServices; 
- using Autodesk.AutoCAD.DatabaseServices; 
- using Autodesk.AutoCAD.Geometry; 
- using Autodesk.AutoCAD.EditorInput; 
- using AcRx = Autodesk.AutoCAD.Runtime; 
- using AcAp = Autodesk.AutoCAD.ApplicationServices; 
- using AcDb = Autodesk.AutoCAD.DatabaseServices; 
- using AcGe = Autodesk.AutoCAD.Geometry; 
- using AcEd = Autodesk.AutoCAD.EditorInput; 
-   
- // This line is not mandatory, but improves loading performances 
- [assembly: ExtensionApplication(typeof(EmrInfo.MyPlugin))] 
-   
- namespace EmrInfo 
- { 
-   public class MyPlugin : IExtensionApplication 
-   { 
-     static bool isRussian = (SystemObjects.DynamicLinker.ProductLcid == 1049); 
-     static List<string> fileNames = new List<string>(); 
-   
-     void IExtensionApplication.Initialize() 
-     { 
-       try 
-       { 
-         string ver = AcAp.Application.GetSystemVariable("_VERNUM") as string; 
-         if (ver.ToUpper().Substring(0, 5) == "I.108") 
-         { 
-           AcAp.Application.DocumentManager.DocumentLockModeChanged += 
-             new AcAp.DocumentLockModeChangedEventHandler(DocumentManager_DocumentLockModeChanged); 
-         } 
-       } 
-       catch { } 
-     } 
-   
-     void IExtensionApplication.Terminate() 
-     { 
-     } 
-   
-     List<AcDb.Database> GetAllXrefedDatabase(AcDb.Database db) 
-     { 
-       List<AcDb.Database> dbs = new List<AcDb.Database>(); 
-       if (db != null) 
-       { 
-         if (!dbs.Contains(db)) dbs.Add(db); 
-         AcDb.XrefGraph xg = db.GetHostDwgXrefGraph(true); 
-         AcDb.XrefGraphNode root = xg.RootNode as AcDb.XrefGraphNode; 
-         for (int i = 0; i < root.NumOut; i++) 
-         { 
-           AcDb.XrefGraphNode node = root.Out(i) as AcDb.XrefGraphNode; 
-           if (node.XrefStatus == AcDb.XrefStatus.Resolved) 
-           { 
-             AcDb.Database db_child = node.Database; 
-             if (db_child != null && !dbs.Contains(db_child)) 
-             { 
-               List<AcDb.Database> dbs_child = GetAllXrefedDatabase(db_child); 
-               for (int j = 0; j < dbs_child.Count; j++) 
-                 if (!dbs.Contains(dbs_child[j])) dbs.Add(dbs_child[j]); 
-             } 
-           } 
-         } 
-       } 
-       return dbs; 
-     } 
-     public void DocumentManager_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e) 
-     { 
-       try 
-       { 
-         AcDb.Database db = e.Document.Database; 
-         List<AcDb.Database> dbs = GetAllXrefedDatabase(db); 
-         string fileNamesString = ""; 
-         for (int i = 0; i < dbs.Count; i++) 
-         { 
-           if (dbs[i].IsEmr && !fileNames.Contains(dbs[i].Filename)) 
-           { 
-             fileNames.Add(dbs[i].Filename); 
-             fileNamesString += ("\n<" + dbs[i].Filename + ">"); 
-           } 
-         } 
-         if (fileNamesString.Length > 0) 
-         { 
-           AcAp.Application.ShowAlertDialog(isRussian ? 
-             "\n!!! ВНИМАНИЕ-ВНИМАНИЕ-ВНИМАНИЕ !!!" + 
-             "\nСледующие чертежи содержат метку ФАЙЛ СОЗДАН В УЧЕБНОЙ ВЕРСИИ ПРОДУКТА:" 
-             + fileNamesString : 
-             "\n!!! ATTENTION-ATTENTION-ATTENTION !!!" + 
-             "\nNext dwg-files has a mark PRODUCED BY AN AUTODESK EDUCATIONAL PRODUCT:" 
-             + fileNamesString 
-           ); 
-         }  
-       } 
-       catch { }; 
-     } 
-      
-     [CommandMethod("CheckEmr")] 
-     public static void CheckEmr() 
-     { 
-       if (AcAp.Application.DocumentManager.MdiActiveDocument.Database.IsEmr) 
-       { 
-         AcAp.Application.ShowAlertDialog(isRussian ? 
-           "ВНИМАНИЕ: Чертеж содержит метку ФАЙЛ СОЗДАН В УЧЕБНОЙ ВЕРСИИ ПРОДУКТА!!!" : 
-           "ATTENTION: Drawing has a mark PRODUCED BY AN AUTODESK EDUCATIONAL PRODUCT!!!"); 
-       } 
-       else 
-       { 
-         AcAp.Application.ShowAlertDialog(isRussian ? 
-           "Чертеж НЕ содержит метку ФАЙЛ СОЗДАН В УЧЕБНОЙ ВЕРСИИ ПРОДУКТА!!!" : 
-           "Drawing has NOT a mark PRODUCED BY AN AUTODESK EDUCATIONAL PRODUCT!!!"); 
-       } 
-     } 
-     [CommandMethod("CheckFilesEmr")] 
-     public static void CheckFilesEmr() 
-     { 
-       AcAp.Document doc = AcAp.Application.DocumentManager.MdiActiveDocument; 
-       if (doc == null) return; 
-       AcEd.Editor ed = doc.Editor; 
-       Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); 
-       openFileDialog.Title = isRussian ? "Выберите dwg-файлы" : "Select dwg-files"; 
-       openFileDialog.Filter = isRussian ? "dwg-файлы|*.dwg" : "dwg-files|*.dwg"; 
-       openFileDialog.Multiselect = true; 
-       bool? bClickedOK = openFileDialog.ShowDialog(); 
-       if (!bClickedOK.HasValue || !bClickedOK.Value) return; 
-       ed.WriteMessage(isRussian ? "\nОбработаны файлы:\n" : "\nProcessed files:\n"); 
-        
-       foreach (string fileName in openFileDialog.FileNames) { 
-         System.Windows.Forms.Application.DoEvents(); 
-         using (AcDb.Database db = new Database(false, false)) 
-         { 
-           try 
-           { 
-             db.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, false, ""); 
-             if (db.IsEmr)  
-               ed.WriteMessage(isRussian ? "\tЕсть метка: {0}\n" : "Has mark: {0}\n", fileName); 
-             else 
-               ed.WriteMessage(isRussian ? "\tНет  метки: {0}\n" : "Has not mark: {0}\n", fileName); 
-           } 
-           catch {} 
-         } 
-       } 
-       ed.WriteMessage(isRussian ? "\nГотово!\n" : "\nDone!\n"); 
-     } 
-   } 
- }