using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
[assembly: CommandClass(typeof(ChangeRowType.MyCommands))]
namespace ChangeRowType
{
public class MyCommands
{
[CommandMethod("ChgRowType")]
public void MyCommand() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
PromptEntityOptions prTab =
new PromptEntityOptions("\nВыберите таблицу для установки типа строки в Header: ");
prTab.SetRejectMessage("Это не таблица!");
prTab.AddAllowedClass(typeof(Table), true);
PromptEntityResult rsTab = ed.GetEntity(prTab);
if (rsTab.Status != PromptStatus.OK)
return;
PromptIntegerOptions prNumRow =
new PromptIntegerOptions("\nУкажите номер строки (нумерация с нуля): ");
prNumRow.AllowNegative = false;
prNumRow.AllowZero = false;
prNumRow.AllowNone = false;
prNumRow.DefaultValue = 2;
PromptIntegerResult rsNumRow = ed.GetInteger(prNumRow);
if (rsNumRow.Status != PromptStatus.OK)
return;
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
Table tab = tr.GetObject(rsTab.ObjectId, OpenMode.ForWrite) as Table;
if (tab != null)
{
tab.Rows[rsNumRow.Value].Style = "_Header";
}
tr.Commit();
}
}
}
}