Skip to content

Commit

Permalink
Fix bug: SketchUp model can't be saved...
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelTallet committed Nov 23, 2019
1 parent 0be91ae commit 20314f5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/pbr/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

require 'sketchup'
require 'pbr/app_observer'
require 'pbr/model_observer'
require 'pbr/menu'
require 'pbr/toolbar'
require 'pbr/viewport'
Expand All @@ -31,6 +32,8 @@ module PBR

Sketchup.add_observer(AppObserver.new)

Sketchup.active_model.add_observer(ModelObserver.new)

# Material Editor is not open yet.
SESSION[:mat_editor_open?] = false

Expand Down
52 changes: 52 additions & 0 deletions source/pbr/model_observer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Physically-Based Rendering extension for SketchUp 2017 or newer.
# Copyright: © 2019 Samuel Tallet <samuel.tallet arobase gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# If you release a modified version of this program TO THE PUBLIC,
# the GPL requires you to MAKE THE MODIFIED SOURCE CODE AVAILABLE
# to the program's users, UNDER THE GPL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# Get a copy of the GPL here: https://www.gnu.org/licenses/gpl.html

raise 'The PBR plugin requires at least Ruby 2.2.0 or SketchUp 2017.'\
unless RUBY_VERSION.to_f >= 2.2 # SketchUp 2017 includes Ruby 2.2.4.

require 'sketchup'
require 'pbr/viewport'

# PBR plugin namespace.
module PBR

# Observes SketchUp model events and reacts.
class ModelObserver < Sketchup::ModelObserver

# rubocop: disable MethodName

# Before a SketchUp model is saved to disk.
def onPreSaveModel(_model)

Viewport.close

end

# After a SketchUp model has been saved to disk.
def onPostSaveModel(_model)

Viewport.open

end

# rubocop: enable MethodName

end

end

0 comments on commit 20314f5

Please sign in to comment.