A video demo which will help give you a holistic view of what a jig is, and its power.
Let’s start with the client class. If you don’t understand this terminology please see a short explanation below this article.
DrawJigWithDynDim jig = new DrawJigWithDynDim(basePt, 500, 500);
if (jig.DragMe() == PromptStatus.OK)
{
}
// instantiate the custom jig object. We are the owners of the
// DrawJigWithDynDim class – it’s our class, not AutoDesk’s.
DrawJigWithDynDim jig = new DrawJigWithDynDim(basePt, 500, 500);
// DragMe() method allows you to move your mouse around and to
// preview various shapes and sizes of proposed entities that will
// be drawn on your monitor. This method returns a PromptStatus
// enum when complete.
if (jig.DragMe() == PromptStatus.OK)
{
// If everything went to plan we can draw the finalised dimensions
// that the jig determined, into the model space.
// We can do this inside the above if statement.
// We could even put this code in the server class, rather than
// here, directly, in the client. Why should the client be responsible
// for how something is drawn? E.g. something like jig.DrawMe(); could be added as a method to the jig server class.
}
// Code which actually adds the final shape that the jig represented,
// is then added into the model space. Perhaps this should more
// appropriately be handled within the jig (server) itself, rather than in the client – but hey – I didn’t write the class.
Now let’s think about how a jig should work, given what we know about it:
-
If we move a mouse, or press a key, then the appearance of the jig should change. For example, when we increase the radius of a circle (taking the circle jig as an example) then the circle that’s drawn on the screen gets bigger and bigger etc.
-
When the jig is over, then the final dimensions and geometric properties of the circle are saved – and it’s all added to the model space.
public class DrawJigWithDynDim : DrawJig
{
public DrawJigWithDynDim(Point3d pt, double w, double h)
{
}
public PromptStatus DragMe()
{
while ((res = ed.Drag(this)).Status == PromptStatus.Other) ;
return (res.Status == PromptStatus.None) ? PromptStatus.OK : res.Status;
}
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
}
}
public class DrawJigWithDynDim : DrawJig
{
// Store the location data that you need as fields in this class.
// When the jig has finished being successfully dragged then
// you need to be able to access the data behind these fields
// from the client class (i.e. the calling class) so that
// you can actually draw what you want to draw.
// I don't like doing this, but it seems to be the practice
// that most .net developers follow.
public DrawJigWithDynDim(Point3d pt, double w, double h)
{
}
public PromptStatus DragMe()
{
// Did the user successfully complete the jig etc., or did
// the user escape from the command?
while ((res = ed.Drag(this)).Status == PromptStatus.Other) ;
return (res.Status == PromptStatus.None) ? PromptStatus.OK : res.Status;
}
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
// The code here is used to actually draw the shape into the
// model space. But when and how often is the shape actually
// drawn? That is dependent upon how far the mouse moves.
// This words hand in hand with the SamplerStatus Sampler
// (JigPrompts prompts) method. Please refer to the explanation
// contained in that method.
// When the user moves the mouse then whats drawn on your screen
// might need to be updated. But what exactly is drawn on your
// screen? That is determined within this method: what is drawn
// and how it is drawn, is determined here.
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
// You receiver a JigPrompts object. Using this object you can know
// where the user’s cursor is. And you can determine: (i) whether
// there is a need to redraw the jig or not, as well as (ii) the
// types of inputs you require in your jig. (You might need to
// add a case statement if you want your jig to have many different
// stages where different types of inputs are collected from the user).
// Every couple of micro seconds, you can check whether the user
// has: (i) moved the mouse, or whether they’ve finished the jig
// and finalised the geometries wanted, or whether they’ve pressed
// cancel. If you’ve moved your mouse by a certain amount (as determined
// by the programmer within this very method) then you can
// ask your new geometries to be redrawn – but only if you the
// programmer have determined whether there is a change. In other
// words, if the mouse has only moved 0.001 units then this is a
// very small amount – there is no need to redraw the entire jig
// given it’s hardly moved. Accordingly you can return a
// SamplerStatus.NoChange to indicate to AutoCAD that there is
// no need to update the geometry of the drawn jig.
// Accordingly, while the geometry is redrawn, you can
// also take the opportunity here to update the
// geometry associated with the shapes/figure that you
// are trying to draw, in the model space.
}
}
Here is the original thread used a source for this tutorial: original Thread
// In this case the client is the `Home` class, and the server class would be the `Person` class.
Class Home
{
private static void Main(string[] args)
{
Person mum = new Person();
mum.VisitMoreOften();
}
}
Thanks for this tutorial. I am wondering if its possible for a jig to apply during the editing of a feature, not just the creation. So in your video example, would it be possible to move the curve and for the dimensions to update automatically? I'm convinced this would require a different mechanism with custom objects and subMoveGrip overrides. Thank you