Tool#draw(view) method will be called 3 times when Style used Back Edges

When I try to get the value of rendering_options[‘RenderMode’] to use in the draw(view) method, the result is wrong and the draw(view) method is called 3 times every time the view is redrawn.
Below is the code to test:

class Tool
  def activate
    @model = Sketchup.active_model
    @rendering_options =  @model.rendering_options
    @rendering_options['DrawBackEdges'] = true unless @rendering_options['DrawBackEdges']
    # view.refresh (view.invalidate) to call draw(view) method
  def draw(view)
    puts "Tool.draw(view)"
    puts "@rendering_options['RenderMode']: #{@rendering_options['RenderMode']}"


I confirm that this only happens when BackEdges is true.
It also happen in SU2020, so this is not new. Please open an issue in the API tracker.

FYI: SketchUp API doc: Sketchup::View#refresh says:


This method might impact performance and if used incorrectly cause instability or crashes. Don’t use this unless you have verified that you cannot use Sketchup::View#invalidate instead.

You can simply scroll the mouse wheel in and out to force a draw() call.

1 Like

Calling view.invalidate in activate should also work.

1 Like