Kean Featured Content Jig dynamic display of coordinates at the drawing interface

Source: Internet
Author: User

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

  1. Using Autodesk.AutoCAD.ApplicationServices;

  2. Using Autodesk.AutoCAD.Runtime;

  3. Using Autodesk.AutoCAD.EditorInput;

  4. Using Autodesk.AutoCAD.Geometry;

  5. Using Autodesk.AutoCAD.GraphicsInterface;

  6. Namespace Jigtextplanartoscreen

  7. {

  8. public class Textjig:drawjig

  9. {

  10. Private Point3D _position;

  11. Public Point3D Position

  12. {

  13. get {return _position;}

  14. }

  15. We ' ll keep our style alive rather than recreating it

  16. Private TextStyle _style;

  17. Public Textjig ()

  18. {

  19. _style = new TextStyle ();

  20. _style. Font =

  21. New FontDescriptor ("Calibri", False, True, 0, 0);

  22. _style. TextSize = 10;

  23. }

  24. protected override Samplerstatus Sampler (jigprompts prompts)

  25. {

  26. Jigpromptpointoptions opts = new Jigpromptpointoptions ();

  27. OPTs. Userinputcontrols =

  28. Userinputcontrols.accept3dcoordinates;

  29. OPTs. Message = "\nselect point:";

  30. Promptpointresult res = prompts. Acquirepoint (opts);

  31. if (res. Status = = Promptstatus.ok)

  32. {

  33. if (_position = = Res. Value)

  34. {

  35. return samplerstatus.nochange;

  36. }

  37. Else

  38. {

  39. _position = Res. Value;

  40. return Samplerstatus.ok;

  41. }

  42. }

  43. return samplerstatus.cancel;

  44. }

  45. protected override bool Worlddraw (Worlddraw Draw)

  46. {

  47. We make use of another interface to push our transforms

  48. WorldGeometry2 WG2 = draw. Geometry as WorldGeometry2;

  49. if (WG2! = null)

  50. {

  51. Push our transforms onto the stack

  52. Wg2. Pushorientationtransform (

  53. Orientationbehavior.screen

  54. );

  55. Wg2. Pushpositiontransform (

  56. Positionbehavior.screen,

  57. New Point2d (30, 30)

  58. );

  59. Draw our screen-fixed text

  60. Wg2. Text (

  61. New Point3D (0, 0, 0),//Position

  62. New Vector3D (0, 0, 1),//Normal

  63. New Vector3D (1, 0, 0),//Direction

  64. _position. ToString (),//Text

  65. True,//rawness

  66. _style//TextStyle

  67. );

  68. Remember to pops our transforms off the stack

  69. Wg2. Popmodeltransform ();

  70. Wg2. Popmodeltransform ();

  71. }

  72. return true;

  73. }

  74. [Commandmethod ("Selpt")]

  75. static public void Selectpointwithjig ()

  76. {

  77. Document doc =

  78. Application.DocumentManager.MdiActiveDocument;

  79. Editor ed = doc. Editor;

  80. Textjig Jig = new Textjig ();

  81. Promptresult res = ed. Drag (jig);

  82. if (res. Status = = Promptstatus.ok)

  83. {

  84. Ed. Writemessage (

  85. "\npoint selected: {0}",

  86. Jig. Position

  87. );

  88. }

  89. }

  90. }

  91. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.