# Drawing a Face on the View with a Ruby Tool

**URL:** <https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007>\
**Category:** Ruby API\
**Tags:** view, tools, draw, quad\
**Created:** [May 7, 2018, 5:26pm UTC](https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007 "2018-05-07T17:26:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 7, 2018, 5:26pm UTC](https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007/1 "2018-05-07T17:26:26Z")

</div>

Continuing the discussion from [Highlighting a Bounding Box (of a Group)](https://forums.sketchup.com/t/highlighting-a-bounding-box-of-a-group/67951/4):

> [@Highlighting a Bounding Box (of a Group)](https://forums.sketchup.com/t/highlighting-a-bounding-box-of-a-group/67951/4):
>
> Is there a way to draw a face?

**YES.** (But they are not really geometric faces.)

Try using [one of the polygon-like GL constants of View#draw](http://ruby.sketchup.com/Sketchup/View.html#draw-instance_method) (the last 6 in the list.)

The [Sketchup::Tool#draw()](http://ruby.sketchup.com/Sketchup/Tool.html#draw-instance_method) documentation actually shows an example  
of drawing a pink filled quad with a crimson border.

Here is another example … paste into the console and type `TestTool.go`  
then click with LMB (repeatedly) in the modeling area to see a “walking” polygon.

```ruby
class TestTool

  def self.go
    Sketchup.active_model.select_tool(self.new)
  end

  def activate
    @start = 0
    @side = 10
    set_points()
  end

  def deactivate(view)
    view.drawing_color= Sketchup::Color.new("Black")
  end

  def draw(view)
    view.drawing_color= Sketchup::Color.new("Orange")
    view.draw(GL_POLYGON, @points)
    @start += @side
  end

  def getExtents()
    Sketchup.active_model.bounds.add(@points)
  end
  
  def onLButtonUp(flags, x, y, view)
    set_points()
    view.refresh # calls getExtents() then draw() method
  end

  def set_points()
    @points = [
      Geom::Point3d.new(@start, 0, 0),
      Geom::Point3d.new(@start+@side, 0, 0),
      Geom::Point3d.new(@start+@side, @side, 0),
      Geom::Point3d.new(@start, @side, 0)
    ]
  end
  
end

```

BTW, the quad walks out of bounds for me and disappears. You can only draw within the model bounds.  
Somewhere there is a method that will recalculate the bounds after you add geometry. (Can’t find it right now.)  
**EDIT** : Steve found it (below,) edited example.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [May 7, 2018, 6:31pm UTC](https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007/2 "2018-05-07T18:31:37Z")

</div>

I think what you want is the Tool’s getExtents method, which tells SketchUp to modify the model’s bounding box.

---

<div class="post-metadata">

**Author:** ![medeek](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/medeek/32/10675_2.png) [@medeek](https://forums.sketchup.com/u/medeek)\
**Post date:** [May 7, 2018, 7:15pm UTC](https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007/3 "2018-05-07T19:15:53Z")

</div>

Very interesting, I may have use for this.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 7, 2018, 7:42pm UTC](https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007/4 "2018-05-07T19:42:25Z")

</div>

> [@slbaumgartner](#):
>
> I think what you want is the Tool’s [getExtents](http://ruby.sketchup.com/Sketchup/Tool.html#getExtents-instance_method) method, which tells SketchUp to modify the model’s bounding box.

Yes, that is the method I was thinking of.

- [`Tool#getExtents()`](http://ruby.sketchup.com/Sketchup/Tool.html#getExtents-instance_method)

Updated example above by adding a `getExtents` method which always  
adds the polygon’s points to the draw bounding box.

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [June 21, 2018, 2:54pm UTC](https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007/5 "2018-06-21T14:54:37Z")

</div>

Also note that the `draw` methods will not draw shaded polygons. It simply draws a polygon with the exact same color you provide it.

I had some experiment at one point that recreated the shading logic of SU… I think I posted it in a thread where Christina also was working on the same thing.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [September 21, 2018, 6:54am UTC](https://forums.sketchup.com/t/drawing-a-face-on-the-view-with-a-ruby-tool/68007/6 "2018-09-21T06:54:41Z")

</div>

Closed on September 21, 2018, 6:54am UTC

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.
