API - Scenes and exporting data attached to objects

Hi - my first post and I’m new to SketchUp & the APIs!

I’m looking a way to export Scenes data, particularly to get a list of elements assigned to each scene. Example dataset to export:

{
  "scenes": [
    {
      "name": "scene1",
      "details": {
        "includeInAnimation": true,
        "name": "Scene 1 Friendly Name",
        "description": "",
        "propertiesToSave": {}
      },
      "elements": ["guid1", "guid2", "guid3"]
    },
    {
      "name": "scene2",
      "details": {
        "includeInAnimation": false,
        "name": "Scene 2 Friendly Name",
        "description": "",
        "propertiesToSave": {}
      },
      "elements": ["guid1", "guid2", "guid3"]
    }
  ]
}

I am a developer and am willing to create an open extension to do this but I’m sure there are people here who have guidance or even a solution. I’m not sure if the API can even do this, it may be that the scene state has to be loaded before data can be exported. I attempted to analyse the SketchUp file exports but couldn’t seem to find this scene data.

In Ruby API

Maybe you already know, former name of the Scenes are Pages.
Therefore you have to look for
https://ruby.sketchup.com/Sketchup/Pages.html

For example to iterate all scenes (pages) you can use:
Pages#each-instance_method

Then to get the “properties” of a scene in quoestion you can use:
https://ruby.sketchup.com/Sketchup/Page.html

For example to check and fill up your hash / json with “includeInAnimation” and description":
Page#include_in_animation=-instance_method
Page#description-instance_method
…and so on


You can look at it, for example:
https://extensions.sketchup.com/search/?q=scene
or
https://sketchucation.com/pluginstore?listtype=1&author=0&category=0&search=scene&submit=%3F
…how others are doing it.


EDIT: Maybe you’re talking about the C API. Then sorry …I don’t know!

Which API ? There is a “live” Ruby API and a C API that can also be used to read .skp files directly in 3rd party applications (or utility programs.)

This is JSON format. Ruby has a built-in JSON library …

This library makes creating JSON text dead simple from a Ruby hash (and hence also from a SketchUp API AttributeDictionary.)

require 'json'

dict = obj.attribute_dictionary("Author_SomeExtension")
if dict # nil if it doesn't exist
  json_attributes = dict.to_h.to_json
end

The main problem (with your assumptions) is that in SketchUp, a drawingelement entity is “owned” by an entities collection. Ie, either the model itself, or a component or group definition.

Scene page objects are views that look at the model. They do not have an entities collection.

But they can keep track of what entities are hidden or shown when they are the selected (current) scene page.


However … there is already a free glTF exporter for SketchUp.

glTF format is JSON.