using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
#pragma warning disable 0618
[assembly: CommandClass(typeof(Rivilis.GetLayoutName))]
namespace Rivilis
{
public class GetLayoutName
{
[CommandMethod("GetLayoutName")]
public void MyCommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityResult rs = ed.GetEntity("\nВыберите примитив: ");
if (rs.Status != PromptStatus.OK) return;
ObjectId id = rs.ObjectId;
using (Entity en = id.Open(OpenMode.ForRead) as Entity) {
ObjectId idBlock = en.BlockId;
using (BlockTableRecord btr = idBlock.Open(OpenMode.ForRead) as BlockTableRecord) {
if (!btr.IsLayout) {
ed.WriteMessage("\nПримитив не на листе!");
return;
} else {
ObjectId idLayout = btr.LayoutId;
using (Layout layout = idLayout.Open(OpenMode.ForRead) as Layout) {
ed.WriteMessage("\nПримитив {0} находится на листе: {1}", id, layout.LayoutName);
}
}
}
}
}
}
}