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(MtextLineSpace.Utils))]
namespace MtextLineSpace
{
public class Utils
{
[CommandMethod("MtextLS")]
public void MyCommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
PromptNestedEntityOptions prEnt =
new PromptNestedEntityOptions("\nВыберите многострочный атрибут:");
PromptEntityResult rsEnt = ed.GetNestedEntity(prEnt);
if (rsEnt.Status != PromptStatus.OK) return;
if (!rsEnt.ObjectId.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(AttributeReference))))
{
ed.WriteMessage("\nЭто не атрибут блока!");
return;
}
using (AttributeReference att = rsEnt.ObjectId.Open(OpenMode.ForWrite) as AttributeReference)
{
if (!att.IsMTextAttribute)
{
ed.WriteMessage("\nЭто не многострочный атрибут!");
return;
}
MText mt = att.MTextAttribute;
double mtls = mt.LineSpaceDistance;
PromptDistanceOptions prDist =
new PromptDistanceOptions("\nУкажите межстрочный интервал");
prDist.AllowZero = false;
prDist.AllowNone = false;
prDist.DefaultValue = mtls;
PromptDoubleResult rsDist = ed.GetDistance(prDist);
if (rsDist.Status == PromptStatus.OK)
{
mt.LineSpaceDistance = rsDist.Value;
att.MTextAttribute = mt;
att.UpdateMTextAttribute();
}
}
}
}
}