[C#] Problem Rotate Circle or Arc with DrawJig
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everybody, i wrote this class here because i need to rotate a list of entity but i can't understand why it doesn't work if in the list there's an arc or a circle. The same thing append if i rotate a blockreference and one of the entity of the pointed block is an arc or a circle. thanks everybody!
class JigRotateObj : DrawJig
{
Point3d _basePoint;
Point3d oldPoint;
Ray _firstAxis;
Ray _lastAxis;
double firstAngle;
double lastAngle;
double angleToDo;
double angleDone;
public int currentInputValue
{
get;
set;
}
public List<ObjectId> _toRotate
{
get;
set;
}
public JigRotateObj(List<ObjectId> toRotate,Point3d basePoint,Ray firstAxis,Ray lastAxis)
{
angleDone = 0;
angleToDo = 0;
oldPoint = Point3d.Origin;
_toRotate = toRotate;
currentInputValue = 1;
_firstAxis = firstAxis;
_firstAxis.BasePoint = basePoint;
_lastAxis = lastAxis;
_lastAxis.BasePoint = basePoint;
_basePoint = basePoint;
}
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
if (currentInputValue == 1)
{
draw.Geometry.Draw(_firstAxis);
}
else
{
draw.Geometry.Draw(_lastAxis);
Transaction trans = AcadUtilities.GetActiveDatabase().TransactionManager.StartTransaction();
Entity app;
foreach (ObjectId obj in _toRotate)
{
app=(Entity)trans.GetObject(obj,OpenMode.ForWrite);
app.TransformBy(Matrix3d.Rotation(angleDone, Vector3d.ZAxis, _basePoint));
app.TransformBy(Matrix3d.Rotation(-angleToDo, Vector3d.ZAxis, _basePoint));
draw.Geometry.Draw(app);
}
angleDone = angleToDo;
trans.Commit();
trans.Dispose();
}
return true;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
PromptPointResult ppr;
if (currentInputValue == 1)
{
ppr = prompts.AcquirePoint("Insert first point");
if (ppr.Value.DistanceTo(oldPoint) < 0.01||ppr.Value.DistanceTo(_firstAxis.BasePoint)<0.01)
return SamplerStatus.NoChange;
if (ppr.Status == PromptStatus.OK)
{
_firstAxis.SecondPoint = ppr.Value;
oldPoint = ppr.Value;
firstAngle = new Line(_basePoint, ppr.Value).Angle;
}
}
else
{
ppr = prompts.AcquirePoint("Insert last point");
if (ppr.Value.DistanceTo(oldPoint) < 0.01 || ppr.Value.DistanceTo(_lastAxis.BasePoint) < 0.01)
return SamplerStatus.NoChange;
if (ppr.Status == PromptStatus.OK)
{
_lastAxis.SecondPoint = ppr.Value;
oldPoint = ppr.Value;
lastAngle = new Line(_basePoint, ppr.Value).Angle;
angleToDo = firstAngle - lastAngle;
}
}
return SamplerStatus.OK;
}