• Login
sketchucation logo sketchucation
  • Login
ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

Using View.draw_text method - a bug?

Scheduled Pinned Locked Moved Plugins
3 Posts 2 Posters 366 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    johnwmcc
    last edited by 25 Apr 2012, 00:10

    I'm running SketchUp v8.0.11752 on Windows Pro 64bit, and trying to get my head round developing a new Tool to draw shapes using a variant of Jim Folger's CLineTool.

    At the moment, I'm trying to understand how to use the View.draw_text method when providing feedback to the user.

    The documentation says that the two arguments are a Point3D object, and a text string to display.

    When I test it using the [0,0,0] representation of a Point3D, the text is shown during the tool's operation at the SCREEN coordinates of [0,0] - right up at the top left of the SketchUp drawing area, NOT at the axis ORIGIN.

    Similarly, if I give it the (3D) input point at the cursor, the text moves with the cursor as expected, but around the top left screen position, going partially out of view some of the time. It seems to be taking only the r and g values of the 3D input point and displaying the text a proportionate amount of right and down displacement from the top left of the drawing viewport.

    Is this a bug? Or am I just not understanding how to feed the cursor location properly to view.draw_text? I'm using the same routine to draw test CLines, and they are starting in the right place both on screen and in the model.

    I've searched this forum, and Googled for view.draw_text, but can't find anything relevant other than the API documentation. I'm still very new to Ruby programming, and so far have only manage minor adaptations of other's code. At least I THINK I now understand how (almost) all of CLineTool works.

    But I don't find it easy to work out from the API docs how to use things for anything more complex than their (usually very simple) examples with static values, if I can't find another plugin that uses it. (And I do have a science and maths background to PhD level).

    Any help would be appreciated.

    John McC

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 25 Apr 2012, 07:38

      The position is a 2D viewport position wrapped in a Geom::Point3d object.

      If you have a 3D model position and want to get the 2D viewport representation of it, use view.screen_coords( point3d )

      <span class="syntaxdefault">pt3d </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">3 </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">pt2d </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">screen_coords</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> pt3d </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">draw_text</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> pt2d</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Hello World'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span>
      

      Yes - the API docs are lacking and often misleading or plain wrong sometimes. 😞

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • J Offline
        johnwmcc
        last edited by 25 Apr 2012, 10:19

        Many thanks. For some non-obvious reason, I didn't even SEE the screen_coords method of the View object. I was looking for an equivalent method or property of the point itself.

        Gratefully....

        John MCC

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          3/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement