/// 模拟AutoCAD移动命令Move
/// </summary>
public void sMoveJig()
{
try
{
PromptSelectionResult psres = ac.ed.GetSelection();
if (psres.Status != PromptStatus.OK)
return;
ents = new Entity;
using (Transaction ctrans = ac.db.TransactionManager.StartTransaction())
{
for (int i = 0; i < psres.Value.Count; i++)
{
Entity ent = (Entity)ctrans.GetObject(psres.Value.ObjectId, OpenMode.ForRead);
ents = (Entity)ent.Clone();
}
ctrans.Commit();
}
PromptPointResult ppRes = ac.ed.GetPoint("\n基准点");
if (ppRes.Status != PromptStatus.OK)
return;
Point3d startPoint = ppRes.Value;
_PrePosition = startPoint;
PromptResult pres = ac.ed.Drag(this);
if (pres.Status == PromptStatus.OK)
{
Vector3d displacementVector = _CurPosition - startPoint;
using (Transaction ctrans = ac.db.TransactionManager.StartTransaction())
{
for (int i = 0; i < psres.Value.Count; i++)
{
Entity ent = (Entity)ctrans.GetObject(psres.Value.ObjectId, OpenMode.ForWrite);
ent.TransformBy(Matrix3d.Displacement(displacementVector));
}
ctrans.Commit();
}
}
}
catch (System.Exception ex)
{
ae.WriteMessage(ex);
}
finally
{
for (int i = 0; i < ents.Length; i++)
{
ents.Dispose();
}
}
} public class aModifyJig : DrawJig
/// <summary>
/// 模拟AutoCAD移动命令Move
/// </summary>
static public void sCmd_Move()
{
aModifyJig tJig = new aModifyJig();
tJig.sMoveJig();
} protected override SamplerStatus Sampler(JigPrompts prompts)
{
try
{
JigPromptPointOptions jpOpt = new JigPromptPointOptions(_Note);
jpOpt.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.InitialBlankTerminatesInput | UserInputControls.NullResponseAccepted);
PromptPointResult userFeedback = prompts.AcquirePoint(jpOpt);
if (userFeedback.Status == PromptStatus.Error) return SamplerStatus.Cancel;
_CurPosition = userFeedback.Value;
if (CursorHasMoved())
{
Vector3d displacementVector = _CurPosition - _PrePosition;
for (int i = 0; i < ents.Length; i++)
{
ents.TransformBy(Matrix3d.Displacement(displacementVector));
}
_PrePosition = _CurPosition;
return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}
catch (System.Exception ex)
{
ae.WriteMessage(ex);
return SamplerStatus.NoChange;
}
} protected override bool WorldDraw(WorldDraw draw)
{
try
{
for (int i = 0; i < ents.Length; i++)
{
draw.Geometry.Draw(ents);
}
}
catch (System.Exception ex)
{
ae.WriteMessage(ex);
}
return true;
}
private bool CursorHasMoved()
{
return !(_CurPosition == _PrePosition);
} /// <summary>
/// 移动并即时显示多个实体
/// Version : 2008.12.12
/// </summary>
/// <param name="objClt">实体集合</param>
/// <param name="basePoint">初始点</param>
/// <param name="showOnly">只是显示,true : 只是显示图形并不把图形画出来;false : 最后会把图形画出来</param>
/// <param name="note"></param>
/// <returns>确认式的结束返回true,放弃或出错返回false</returns>
public bool MoveJig(DBObjectCollection objClt, Point3d basePoint, bool showOnly, string note)
{
try
{
//_Note = note;
ents = new Entity;
for (int i = 0; i < objClt.Count; i++)
{
ents = (Entity)objClt.Clone();
}
_PrePosition = basePoint;
PromptResult pRes = ac.ed.Drag(this);
if (pRes.Status == PromptStatus.OK)
{
Vector3d displacementVector = _CurPosition - basePoint;
for (int i = 0; i < objClt.Count; i++)
{
Entity ent = (Entity)objClt;
ent.TransformBy(Matrix3d.Displacement(displacementVector));
}
if (showOnly)
return true;
else
{
an.DrawEntity(objClt, aEntclls.Null, false);
return true;
}
}
else
return false;
}
catch (System.Exception ex)
{
ae.WriteMessage(ex);
}
finally
{
for (int i = 0; i < ents.Length; i++)
{
ents.Dispose();
}
}
return false;
} /// <summary>
/// 模拟AutoCAD复制命令Copy
/// </summary>
static public void sCmd_Copy()
{
aModifyJig tJig = new aModifyJig();
tJig.sCopyJig();
}
/// <summary>
/// 模拟AutoCAD复制命令Copy
/// </summary>
public void sCopyJig()
{
try
{
PromptSelectionResult psRes = ac.ed.GetSelection();
if (psRes.Status != PromptStatus.OK) return;
ents = new Entity;
using (Transaction ctrans = ac.db.TransactionManager.StartTransaction())
{
for (int i = 0; i < psRes.Value.Count; i++)
{
Entity ent = (Entity)ctrans.GetObject(psRes.Value.ObjectId, OpenMode.ForRead);
ents = (Entity)ent.Clone();
}
ctrans.Commit();
}
aApp.SetSystemVariable("OSMODE", 16383);
_PrePosition = ac.ed.GetPoint("\nBase Point").Value;
PromptResult pres = ac.ed.Drag(this);
if (pres.Status == PromptStatus.OK)
{
DBObjectCollection dbClt = new DBObjectCollection();
for (int i = 0; i < ents.Length; i++)
{
dbClt.Add(ents);
}
an.DrawEntity(dbClt, aEntclls.Null, false);
}
else
{
for (int i = 0; i < ents.Length; i++)
{
ents.Dispose();
}
}
}
catch (System.Exception ex)
{
ae.WriteMessage(ex);
for (int i = 0; i < ents.Length; i++)
{
ents.Dispose();
}
}
} 本帖最后由 carrot1983 于 2020-9-30 21:28 编辑
移动的时候不要显示原对象的原位置。看样子是DRAWJIG闪烁的问题。是真无解。
2020.10.07
记录一下,这一刻,
DrawJig不闪烁的解决办法:硬件加速要打勾。 2020.10.11
在硬件加速的前提下。发现有两个系统变量。DRAGP1和DRAGP2 确实值得纪念 按楼主方法 我的也不闪烁了 原来命令行一直提示重生成已终止
页:
1
[2]