using System;
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
{
List<string> fileNames = new List<string>();
void IExtensionApplication.Initialize()
{
AcAp.Application.DocumentManager.DocumentLockModeChanged +=
new AcAp.DocumentLockModeChangedEventHandler(DocumentManager_DocumentLockModeChanged);
}
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(
"\n!!! ВНИМАНИЕ-ВНИМАНИЕ-ВНИМАНИЕ !!!" +
"\nСледующие чертежи содержат Штамп Учебной Версии:"
+ fileNamesString);
}
}
catch { };
}
}
}