using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
namespace ArxHlb
{
public class CADJig
{
/// <summary>
/// 入口函数
/// </summary>
/// <param name="ed">ed</param>
/// <param name="lstEnt">实体列表</param>
/// <param name="promp">提示</param>
/// <returns></returns>
public static bool Jig(Editor ed, List<Entity> lstEnt, Point3d pt, string promp)
{
Jig jig = new Jig();
jig.lstEnt = lstEnt;
jig.ptBase = pt;
jig.promp = promp;
PromptResult prJig = ed.Drag(jig);
if (prJig.Status != PromptStatus.OK)
{
return false;
}
else
{
return true;
}
}
}
//本类是Jig,单独的实体或实体列表均可调用
public class Jig : DrawJig
{
private List<Entity> _lstEnt; //移动的实体
private Point3d _ptBase; //基点
private string _promp; //提示
/// <summary>
/// 移动的实体
/// </summary>
public List<Entity> lstEnt
{
set { _lstEnt = value; }
}
/// <summary>
/// 基点
/// </summary>
public Point3d ptBase
{
set { _ptBase = value; }
get { return _ptBase; }
}
/// <summary>
/// /提示
/// </summary>
public string promp
{
set { _promp = value; }
}
private Point3d ptTo; //插入点
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions optJigPoint = new JigPromptPointOptions(_promp);
//optJigPoint.Cursor = CursorType.RubberBand;
optJigPoint.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted |
UserInputControls.NullResponseAccepted;
optJigPoint.Keywords.Add("Undo", "Undo", "放弃(U)");
PromptPointResult resJigPoint = prompts.AcquirePoint(optJigPoint);
Point3d curPt = resJigPoint.Value;
if (ptTo != curPt)
{
ptTo = curPt;
return SamplerStatus.OK;
}
else
{
ptBase = ptTo;
return SamplerStatus.NoChange;
}
}
protected override bool WorldDraw(WorldDraw draw)
{
try
{
Matrix3d mat = Matrix3d.Displacement(ptTo - ptBase);
foreach (Entity ent in _lstEnt)
{
//移动每个实体
ent.TransformBy(mat);
ent.RecordGraphicsModified(true);
draw.Geometry.Draw(ent);
}
}
catch (System.Exception)
{
return false;
}
return true;
}
}
}
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
namespace ArxHlb
{
public class CADJig
{
/// <summary>
/// 入口函数
/// </summary>
/// <param name="ed">ed</param>
/// <param name="lstEnt">实体列表</param>
/// <param name="promp">提示</param>
/// <returns></returns>
public static bool Jig(Editor ed, List<Entity> lstEnt, Point3d pt, string promp)
{
Jig jig = new Jig();
jig.lstEnt = lstEnt;
jig.ptBase = pt;
jig.promp = promp;
PromptResult prJig = ed.Drag(jig);
if (prJig.Status != PromptStatus.OK)
{
return false;
}
else
{
return true;
}
}
}
//本类是Jig,单独的实体或实体列表均可调用
public class Jig : DrawJig
{
private List<Entity> _lstEnt; //移动的实体
private Point3d _ptBase; //基点
private string _promp; //提示
/// <summary>
/// 移动的实体
/// </summary>
public List<Entity> lstEnt
{
set { _lstEnt = value; }
}
/// <summary>
/// 基点
/// </summary>
public Point3d ptBase
{
set { _ptBase = value; }
get { return _ptBase; }
}
/// <summary>
/// /提示
/// </summary>
public string promp
{
set { _promp = value; }
}
private Point3d ptTo; //插入点
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions optJigPoint = new JigPromptPointOptions(_promp);
//optJigPoint.Cursor = CursorType.RubberBand;
optJigPoint.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted |
UserInputControls.NullResponseAccepted;
optJigPoint.Keywords.Add("Undo", "Undo", "放弃(U)");
PromptPointResult resJigPoint = prompts.AcquirePoint(optJigPoint);
Point3d curPt = resJigPoint.Value;
if (ptTo != curPt)
{
ptTo = curPt;
return SamplerStatus.OK;
}
else
{
ptBase = ptTo;
return SamplerStatus.NoChange;
}
}
protected override bool WorldDraw(WorldDraw draw)
{
try
{
Matrix3d mat = Matrix3d.Displacement(ptTo - ptBase);
foreach (Entity ent in _lstEnt)
{
//移动每个实体
ent.TransformBy(mat);
ent.RecordGraphicsModified(true);
draw.Geometry.Draw(ent);
}
}
catch (System.Exception)
{
return false;
}
return true;
}
}
}