How do I clear the active model using ruby API?

Hi Dan,

Thanks for the sample code.

From this discussion, I assume that on the Mac Sketchup maintains one-to-one correspondence between a model, an NSDocument and a document view. That is unclear from the documentation. If so, then the model’s modified status is actually the NSDocument modified status which is determined by NSChangeCount. NSChangeCount provides logic for discardable changes such as those changes made by the API. Changes made by the API could add the NSChangeDiscardable flag to NSChangeDone when calling updateChangeCount, i.e., [document. updateChangeCount NSChangeDone| NSChangeDiscardable]. NSDocument would not autosave or prompt to save the document on close if all recorded changes are discardable.

One other annoyance: When the app is relaunched, Sketchup conveniently restores windows that were open in the last session including Entity Information, Layers, etc., but not the Ruby console window which is never automatically reopened except to display Ruby syntax errors. Ruby execution error diagnostics are lost unless I reopen the Ruby console before running my script. So I have to reopen the Ruby console every time I relaunch Sketchup unless I am confident that my script has no bugs.

Best regards,
Bob Rice

When I develop I load the extension from outside the Plugins directory, this is in order to keep the work in version control like Git. To load the extensions I have a “proxy loader” in my Plugins folder with something like this:

SKETCHUP_CONSOLE.show

paths = [
  'C:/Users/Thomas/SourceTree/tt-library-2',
  'C:/Users/Thomas/SourceTree/TestUp2/src',
  'C:/Users/Thomas/SourceTree/SpeedUp/src',
  'C:/Users/Thomas/SourceTree/solid-inspector/src',
  # 'C:/Users/Thomas/SourceTree/solid-inspector',
  'C:/Users/Thomas/SourceTree/SelectionTools/src',
  'C:/Users/Thomas/SourceTree/su_colorize/src',
  # 'C:/Users/Thomas/SourceTree/sketchup-ruby-api-tutorials',
  'C:/Users/Thomas/SourceTree/PlaceComponent/src',
]

paths.each { |path|
  $LOAD_PATH << path
  ruby_files_filter = File.join(path, '*.rb')
  Dir.glob(ruby_files_filter) { |filename|
    Sketchup.require filename
  }
}

That way the Ruby Console pops up before my extensions load and I can catch all details.

I’ve made a plugin for opening the console on start. This has the benefit that you can turn it on and off from the Window menu, e.g. if you primarily use SU for drawing for a period, not extension development.

https://extensions.sketchup.com/en/content/eneroth-console-opener