Author Topic: AU 2005 code - Part 6 "Doin' the Jig"  (Read 2739 times)

0 Members and 1 Guest are viewing this topic.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
AU 2005 code - Part 6 "Doin' the Jig"
« on: December 28, 2005, 02:53:00 PM »
or dynamic graphics, or ghosting, or whatever you want to call it.  This example will "ghost" a circle around your crosshair.

To create a custom Jig you must subclass from one of the available Jig classes.  Depending on the class that you derrive from there will be a number of methods that you must override.  This class is derrived from the DrawJig class and the Sampler and WorldDraw methods are overriden.

Code: [Select]
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.ApplicationServices;

namespace AU2005.AcadApi
{
//Pages 12 & 13
//New class derrived from the DrawJig class
public class JigExample : DrawJig
{
#region private member fields
private Point3d previousCursorPosition;
private Point3d currentCursorPosition;
private Entity entityToDrag;
#endregion


[CommandMethod("StartJig")]
public void StartJig()
{
//Initialize cursor position
//Use the geometry library to create a new 3d point object
previousCursorPosition = new Point3d (0,0,0);

entityToDrag = new Circle(new Point3d(0,0,0), new Vector3d (0,0,1), 6);

Application.DocumentManager.MdiActiveDocument.Editor.Drag(this);
}


//You must override this method
protected override SamplerStatus Sampler(JigPrompts prompts)
{
//Get the current cursor position
PromptPointResult userFeedback = prompts.AcquirePoint();
currentCursorPosition = userFeedback.Value;

if (CursorHasMoved())
{
//Get the vector of the move
Vector3d displacementVector = currentCursorPosition.GetVectorTo(previousCursorPosition);

//Transform the circle to the new location
entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));

//Save the cursor position
previousCursorPosition = currentCursorPosition;

return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}


//You must override this method
protected override bool WorldDraw(WorldDraw draw)
{
draw.Geometry.Draw(entityToDrag);

return true;
}


private bool CursorHasMoved ()
{
return !(currentCursorPosition == previousCursorPosition);
}
}
}

Bobby C. Jones