public class TableJigger : EntityJig
{
private double tolerance = 0.0001;
private Point3d insertPoint;
public TableJigger(Entity entity)
: base(entity)
{ }
protected override bool Update()
{
(this.Entity as Table).Position = this.insertPoint;
(this.Entity as Table).GenerateLayout();
return true;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions ppo = new JigPromptPointOptions("Укажите точку вставки таблицы");
ppo.UserInputControls = UserInputControls.GovernedByUCSDetect;
PromptPointResult res = prompts.AcquirePoint(ppo);
if (res.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
if (res.Value.IsEqualTo(insertPoint, new Tolerance(tolerance, tolerance)))
return SamplerStatus.NoChange;
insertPoint = res.Value;
return SamplerStatus.OK;
}
public static PromptResult Jig(Table table)
{
PromptResult result = null;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
TableJigger jigger = new TableJigger(table);
result = ed.Drag(jigger);
if (result.Status == PromptStatus.OK)
{
BlockTableRecord currSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
currSpace.AppendEntity(table);
tr.AddNewlyCreatedDBObject(table, true);
db.TransactionManager.QueueForGraphicsFlush();
}
tr.Commit();
}
return result;
}
}