using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(Rivilis.MLeaderScale))]
namespace Rivilis
{
public class MLeaderScale
{
[CommandMethod("MLeaderScale", CommandFlags.Modal)]
public void MyCommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions prEnt = new PromptEntityOptions("\nВыберите мультилидер");
prEnt.SetRejectMessage("\nЭто не мультилидер");
prEnt.AddAllowedClass(typeof(MLeader), true);
PromptEntityResult rsEnt = ed.GetEntity(prEnt);
if (rsEnt.Status != PromptStatus.OK) return;
ObjectContextManager ocm = db.ObjectContextManager;
ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
ObjectContext curAnnoScale = occ.GetContext(db.Cannoscale.Name);
using (MLeader ml = rsEnt.ObjectId.Open(OpenMode.ForWrite) as MLeader)
{
if (ml.Annotative == AnnotativeStates.True) {
AddScale(ml, curAnnoScale, occ);
if (ml.ContentType == ContentType.MTextContent)
{
MText mt = ml.MText;
if (mt.Annotative == AnnotativeStates.True)
{
AddScale(mt, curAnnoScale, occ);
ml.MText = mt;
}
}
}
}
}
void AddScale(Entity ent, ObjectContext curScale, ObjectContextCollection occ)
{
ent.AddContext(curScale);
foreach (ObjectContext scale in occ) {
if (scale.Name != curScale.Name && ent.HasContext(scale))
ent.RemoveContext(scale);
}
}
}
}