Second, dynamic display of coordinates in the drawing interface
Original reproduced from: http://through-the-interface.typepad.com/through_the_interface/jigs/(the mouth is inaccessible)
Accessible reprint entrance: http://bbs.mjtd.com/thread-75618-1-1.html (reprinted from The Mirror Channel by Snow Mountain Flying Fox _lzh)
The original Kean blog has been unable to see, so reprinted by the passage of the snow-capped mountain flying fox _lzh teacher finishing Content
1.kean Blog Original Translation
December 12, 2008
Drawing text planar to the screen inside AutoCAD ' s Drawing window using. NET
Draw flat text to the screen in the AutoCAD drawing window using. Net
I ' ve often seen the question, over the years, the "How to" draw text in the plane of the "the screen", even when the
Over the years, I have often seen such questions as how to draw text on the screen plane, even when the current view is not flat for the current user coordinate system
Current view isn't planar to the current UCS. This ability to the "screen fix" text have been there, but have required
The ability to position text on the screen is present, but requires a series of change techniques
A number of sometimes tricky transformations to get the right behaviour. Well, during a recent internal
To get the right results, after a recent internal discussion,
Discussion I became aware of a really handy facility inside AutoCAD which allows you to dependably draw screen-fixed text Without jumping through hoops.
I'm starting to realize that there's a really handy way in CAD content that allows us to get reliable, fixed screen text without succumbing to transformations
In the example, we ' re implementing a drawjig-a jig that doesn ' t host an entity but allows us to
Implement a Worlddraw () callback for something to being Drawn-which draws text at a fixed screen location with a fixed siz E and orientation.
In this simple example, we will implement a subclass of Drawjig (a drag type can host an entity and allow us to implement a Worlddraw method to back and forth some of the things we need to draw), and he can draw the text at a fixed position with a fixed size and coordinate origin.
Our code takes the simple task of asking the user to select a point, and shows the current cursor location during the drag At an offset of $, from the bottom left corner of the drawing window.
Our code performs a simple task, answering a point selected by the user, and displaying the position of the cursor at the lower-left corner of the current drawing window (30,30) at the offset of the coordinate point in the drag process
Here ' s the C # code:
Here is the C # code
Using Autodesk.AutoCAD.ApplicationServices;
Using Autodesk.AutoCAD.Runtime;
Using Autodesk.AutoCAD.EditorInput;
Using Autodesk.AutoCAD.Geometry;
Using Autodesk.AutoCAD.GraphicsInterface;
Namespace Jigtextplanartoscreen
{
public class Textjig:drawjig
{
Private Point3D _position;
Public Point3D Position
{
get {return _position;}
}
We ' ll keep our style alive rather than recreating it
Private TextStyle _style;
Public Textjig ()
{
_style = new TextStyle ();
_style. Font =
New FontDescriptor ("Calibri", False, True, 0, 0);
_style. TextSize = 10;
}
protected override Samplerstatus Sampler (jigprompts prompts)
{
Jigpromptpointoptions opts = new Jigpromptpointoptions ();
OPTs. Userinputcontrols =
Userinputcontrols.accept3dcoordinates;
OPTs. Message = "\nselect point:";
Promptpointresult res = prompts. Acquirepoint (opts);
if (res. Status = = Promptstatus.ok)
{
if (_position = = Res. Value)
{
return samplerstatus.nochange;
}
Else
{
_position = Res. Value;
return Samplerstatus.ok;
}
}
return samplerstatus.cancel;
}
protected override bool Worlddraw (Worlddraw Draw)
{
We make use of another interface to push our transforms
WorldGeometry2 WG2 = draw. Geometry as WorldGeometry2;
if (WG2! = null)
{
Push our transforms onto the stack
Wg2. Pushorientationtransform (
Orientationbehavior.screen
);
Wg2. Pushpositiontransform (
Positionbehavior.screen,
New Point2d (30, 30)
);
Draw our screen-fixed text
Wg2. Text (
New Point3D (0, 0, 0),//Position
New Vector3D (0, 0, 1),//Normal
New Vector3D (1, 0, 0),//Direction
_position. ToString (),//Text
True,//rawness
_style//TextStyle
);
Remember to pops our transforms off the stack
Wg2. Popmodeltransform ();
Wg2. Popmodeltransform ();
}
return true;
}
[Commandmethod ("Selpt")]
static public void Selectpointwithjig ()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed = doc. Editor;
Textjig Jig = new Textjig ();
Promptresult res = ed. Drag (jig);
if (res. Status = = Promptstatus.ok)
{
Ed. Writemessage (
"\npoint selected: {0}",
Jig. Position
);
}
}
}
}
Now let's see our SELPT command in action.
First in a fairly standard view:and now in an arbitrary 3D view:
OK, that's it for today. Right now I ' m at our Developer Day event in Paris, and after this I ' m taking a four-week break over the holiday season. Which means my blog output is likely to slow down (to a trickle, perhaps even stop completely) over the coming weeks. So-just in Case-i ' d like to wish all the readers of "Through the Interface," all the very best for the holiday season. Thank You-your continued support and readership over the last year, here's looking forward to a fun and productive 200 9! :-)
Graphical display of 2.Kean code implementations:
Kean Featured Content Jig dynamic display of coordinates at the drawing interface