using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(RotateEntity.MyCommands))]
namespace RotateEntity
{
public class MyCommands
{
[CommandMethod("RTE", CommandFlags.Modal)]
public void MyCommand()
{
// Put your command code here
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
PromptEntityOptions enOpt =
new PromptEntityOptions("\nВыберите примитив: ");
PromptEntityResult enRes = ed.GetEntity(enOpt);
if (enRes.Status != PromptStatus.OK) return;
PromptPointOptions ptOpt =
new PromptPointOptions("\nУкажите базовую точку: ");
PromptPointResult ptRes = ed.GetPoint(ptOpt);
if (ptRes.Status != PromptStatus.OK) return;
// Базовая точка в МСК
Point3d pBase = ptRes.Value.TransformBy(ucs);
PromptAngleOptions angOpt =
new PromptAngleOptions("\nУкажите угол поворота (ENTER - завершение): ");
angOpt.BasePoint = ptRes.Value; angOpt.UseBasePoint = true;
angOpt.AllowNone = true; // Для завершения команды по ENTER
while (true) {
PromptDoubleResult angRes = ed.GetAngle(angOpt);
if (angRes.Status != PromptStatus.OK) break;
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
Entity ent = tr.GetObject(enRes.ObjectId, OpenMode.ForWrite) as Entity;
Matrix3d mat = Matrix3d.Rotation(angRes.Value, Vector3d.ZAxis, pBase);
ent.TransformBy(mat);
tr.Commit();
}
}
}
}
}