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(TextNearCursor.MyCommands))]
namespace TextNearCursor
{
public class MyCommands
{
[CommandMethod("TestPT")]
public void TestPTHandler()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
ed.PointMonitor += Ed_PointMonitor;
PromptPointResult rs;
PromptPointOptions opt =
new PromptPointOptions("Укажите очередную точку (ENTER - завершение): ");
opt.AllowNone = true;
do {
rs = ed.GetPoint(opt);
} while (rs.Status == PromptStatus.OK);
ed.PointMonitor -= Ed_PointMonitor;
}
private void Ed_PointMonitor(object sender, PointMonitorEventArgs e)
{
if (e.Context.PointComputed) {
double height = (double)Application.GetSystemVariable("VIEWSIZE") * 0.02;
string s = string.Format("{0},{1},{2}",
e.Context.ComputedPoint.X, e.Context.ComputedPoint.Y, e.Context.ComputedPoint.Z);
Autodesk.AutoCAD.GraphicsInterface.TextStyle style =
new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
style.FromTextStyleTableRecord(HostApplicationServices.WorkingDatabase.Textstyle);
style.TextSize = height;
e.Context.DrawContext.Geometry.Text(
e.Context.ComputedPoint + new Vector3d(height, height, 0),
e.Context.DrawContext.Viewport.ViewDirection,
Vector3d.XAxis,
s, false, style);
}
}
}
}