# Error on API documentation view.draw2d

**URL:** <https://forums.sketchup.com/t/error-on-api-documentation-view-draw2d/140660>\
**Category:** Ruby API\
**Created:** [October 29, 2020, 1:59pm UTC](https://forums.sketchup.com/t/error-on-api-documentation-view-draw2d/140660 "2020-10-29T13:59:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [October 29, 2020, 1:59pm UTC](https://forums.sketchup.com/t/error-on-api-documentation-view-draw2d/140660/1 "2020-10-29T13:59:33Z")

</div>

Hi all,

I try to display an jpg image in Sketchup windows

When I copy and past the following code from the [documentation](https://ruby.sketchup.com/Sketchup/View.html#load_texture-instance_method) I got an error:

```auto
module Example
  class MyTool

    def activate
      view = Sketchup.active_model.active_view
      image_rep = view.model.materials.current.texture.image_rep
      @texture_id = view.load_texture(image_rep)
    end

    def deactivate(view)
      view.release_texture(@texture_id)
    end

    def draw(view)
      points = [[0, 0, 0], [9, 0, 0], [9, 9, 0], [0, 9, 0] ]
      uvs = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0] ]
      view.draw(points, texture_id: @texture_id, uvs: uvs)
    end

  end
end
Sketchup.active_model.select_tool(Example::MyTool.new)

```

=\>

```
Error: #<TypeError: no implicit conversion of Array into Integer>
<main>:16:in `draw'
<main>:16:in `draw'

```

So I had the the openglenum and its start working, but I don’t know how to map texture. Wich openglnum should I use ? what shoud be the UV

```
module Example
  class MyTool

    def activate
      view = Sketchup.active_model.active_view
      image_rep = view.model.materials.current.texture.image_rep
      puts "image_rep#{image_rep}<-"

      @texture_id = view.load_texture(image_rep)
    end

    def deactivate(view)
      view.release_texture(@texture_id)
    end

    def draw(view)
    a = 100
      points = [[a, a, 0], [a*2, a, 0], [a*2, a*2, 0], [a, a*2, 0] ]
      uvs = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0] ]
      #view.draw(GL_POLYGON,points, texture_id: @texture_id, uvs: uvs)
      view.draw2d(GL_QUADS,points, texture_id: @texture_id, uvs: uvs)
      #GL_POLYGON
      #GL_QUADS
      #GL_QUAD_STRIP
    end

  end
end
Sketchup.active_model.select_tool(Example::MyTool.new)

```

Thanks for your help

---

<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:** [October 29, 2020, 6:25pm UTC](https://forums.sketchup.com/t/error-on-api-documentation-view-draw2d/140660/2 "2020-10-29T18:25:50Z")

</div>

The erroneous documentation code example has already been reported in the official issue tracker …

> <https://github.com/SketchUp/api-issue-tracker/issues/445>
>
> The documentation for View.load\_texture here:
> 
> http://ruby.sketchup.com/Sketch…up/View.html#load\_texture-instance\_method
> 
> contains the following example:
> 
> \`\`\`ruby
> module Example
> class MyTool
> 
> def activate
> view = Sketchup.active\_model.active\_view
> image\_rep = view.model.materials.current.texture.image\_rep
> @texture\_id = view.load\_texture(image\_rep)
> end
> 
> def deactivate(view)
> view.release\_texture(@texture\_id)
> end
> 
> def draw(view)
> points = \[\[0, 0, 0\], \[9, 0, 0\], \[9, 9, 0\], \[0, 9, 0\] \]
> uvs = \[\[0, 0, 0\], \[1, 0, 0\], \[1, 1, 0\], \[0, 1, 0\] \]
> view.draw(points, texture\_id: @texture\_id, uvs: uvs)
> end
> 
> end
> end
> Sketchup.active\_model.select\_tool(Example::MyTool.new)
> \`\`\`
> In the draw method, the call to view.draw omits the first parameter for openglenum. I also think the hash key for :texture\_id should be :texture and I'm going to log that as a separate issue.
> 
> So this line:
> \`\`\`ruby
> view.draw(points, texture\_id: @texture\_id, uvs: uvs)
> \`\`\`
> Should be something like:
> \`\`\`ruby
> view.draw(GL\_QUADS, points, texture: @texture\_id, uvs: uvs)        
> \`\`\`

There is also a code example error as the examples show the wrong options hash key for the texture id …

[https://github.com/SketchUp/api-issue-tracker/issues/446](https://github.com/SketchUp/api-issue-tracker/issues/446)

---

<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:** [October 29, 2020, 7:08pm UTC](https://forums.sketchup.com/t/error-on-api-documentation-view-draw2d/140660/3 "2020-10-29T19:08:25Z")

</div>

Okay, after testing the limited example in the docs ([`Sketchup::View#load_texture`](https://ruby.sketchup.com/Sketchup/View.html#load_texture-instance_method) and [`Sketchup::View#release_texture`](https://ruby.sketchup.com/Sketchup/View.html#release_texture-instance_method)) is **not a full working example**!

Here is an example that works (and uses better practice) …

```ruby
module Example
  class MyTool

    def activate
      view = Sketchup.active_model.active_view
      @points = [[0, 0, 0], [9, 0, 0], [9, 9, 0], [0, 9, 0] ]
      @uvs = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0] ]
      @extents = Sketchup.active_model.bounds.add(@points)
      @color = Sketchup::Color.new(0, 0, 255)
      matl = view.model.materials.current
      # The current material might be nil just after model load.
      # Also the current selected material may not have a texture:
      if matl && matl.texture
        image_rep = matl.texture.image_rep
        @texture_id = view.load_texture(image_rep)
      else
        @texture_id = nil
      end
    rescue => err
      puts err.inspect
    ensure
      view.invalidate # redraw the view immediately
    end

    def deactivate(view)
      view.release_texture(@texture_id) if @texture_id
      view.invalidate # redraw the view when done
    end

    def draw(view)
      view.line_stipple = '' # Solid line
      view.drawing_color = @color
      if @texture_id
        view.draw(GL_QUADS, @points, texture: @texture_id, uvs: @uvs)
      else
        view.draw(GL_QUADS, @points)
      end
    end

    def getExtents
      @extents
    end

    def onMouseMove(flags, x, y, view)
      view.invalidate # redraw the view on mousemove
    end

  end
end

Sketchup.active_model.select_tool(Example::MyTool.new)

```

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [October 30, 2020, 10:03am UTC](https://forums.sketchup.com/t/error-on-api-documentation-view-draw2d/140660/4 "2020-10-30T10:03:10Z")

</div>

Thanks you @DanRathbun, your the best !  
I just reverse the texture uv and it works ! perfectly !
