马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
按照Arx例子写了一个块的拖动类,有两个动作:移动和旋转
移动取点,旋转取角度
代码中PromptPointResult res = prompts.AcquirePoint(jigOpts);是取点的动作,想改为AcquireAngle一直没有成功
代码如下:
[C#] 纯文本查看 复制代码 using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
namespace TlsCad
{
public class BlockRefJig:EntityJig
{
Point3d mPosition;
double mAngle;
int mPromptCounter;
public BlockRefJig(ObjectId id):base(new BlockReference(new Point3d(0,0,0),id))
{
mPosition=new Point3d(0,0,0);
mAngle=0;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptOptions jigOpts = new JigPromptOptions();
if(mPromptCounter == 0)
{
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted );
jigOpts.Message = "\n请输入基点:";
PromptPointResult dres = prompts.AcquirePoint(jigOpts);
Point3d positionTemp = dres.Value;
if(positionTemp != mPosition)
{
mPosition = positionTemp;
}
else
return SamplerStatus.NoChange;
if(dres.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
else if (mPromptCounter == 1)
{
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoNegativeResponseAccepted);
jigOpts.BasePoint = mPosition;
jigOpts.UseBasePoint = true;
jigOpts.Message = "\n请输入旋转角度:";
double angleTemp = -1;
PromptPointResult res = prompts.AcquirePoint(jigOpts);
Point3d AnglePnt = res.Value;
angleTemp = AnglePnt.GetVectorTo(mPosition).AngleOnPlane(
new Plane(
Application.DocumentManager.MdiActiveDocument.Database.Ucsorg,
Application.DocumentManager.MdiActiveDocument.Database.Ucsxdir,
Application.DocumentManager.MdiActiveDocument.Database.Ucsydir
));
if (angleTemp != mAngle)
mAngle = angleTemp;
else
return SamplerStatus.NoChange;
if(res.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}
protected override bool Update()
{
try
{
((BlockReference)Entity).Position=mPosition;
((BlockReference)Entity).Rotation =mAngle;
}
catch(System.Exception)
{
return false;
}
return true;
}
public void setPromptCounter(int i)
{
mPromptCounter = i;
}
public Entity GetEntity()
{
return Entity;
}
}
}
2007下,下面修改了一些BUG
[C#] 纯文本查看 复制代码 using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
namespace TlsCad
{
public class BlockRefJig:EntityJig
{
Point3d mPosition;
double mAngle;
int mPromptCounter;
public BlockRefJig(ObjectId id):base(new BlockReference(new Point3d(0,0,0),id))
{
mPosition=new Point3d(0,0,0);
mAngle=0;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
if(mPromptCounter == 0)
{
JigPromptPointOptions jigOpts = new JigPromptPointOptions();
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted );
jigOpts.Message = "\n请输入基点:";
PromptPointResult res = prompts.AcquirePoint(jigOpts);
Point3d positionTemp = res.Value;
if(positionTemp != mPosition)
{
mPosition = positionTemp;
}
else
return SamplerStatus.NoChange;
if(res.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
else if (mPromptCounter == 1)
{
JigPromptAngleOptions jigOpts = new JigPromptAngleOptions();
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoNegativeResponseAccepted);
jigOpts.BasePoint = mPosition;
jigOpts.UseBasePoint = true;
jigOpts.Message = "\n请输入旋转角度:";
PromptDoubleResult res = prompts.AcquireAngle(jigOpts);
double angleTemp = res.Value;
if (angleTemp != mAngle)
mAngle = angleTemp;
else
return SamplerStatus.NoChange;
if (res.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}
protected override bool Update()
{
try
{
((BlockReference)Entity).Position=mPosition;
((BlockReference)Entity).Rotation =mAngle;
}
catch(System.Exception)
{
return false;
}
return true;
}
public void setPromptCounter(int i)
{
mPromptCounter = i;
}
public Entity GetEntity()
{
return Entity;
}
}
} |