Exporting Camera with C sdk



I’m trying to get camera data from skp file for my software… All I found on the documentation and this forum are very confusing.

I get the main camera via SUModelGetCamera, but there is no aspectRatio… And I would like to have all the point of view stored into the file.
I tried to get scenes via SUModelGetScenes but I didn’t find cameras.
I saw on this thread that there is data relative to cameras at the root of the model, but I didn’t find how to access them…

So, how could I collect camera data of a sketchup model via the C sdk ?
Thanks by advance,


You mean you didn’t find the function?

If you you find that some return NULL it’s because by default there is no aspect ratio set and SketchUp display whatever fits in the viewport.


That was related to the Advanced Camera Tools extension - is that what you are looking for here?


You mean you didn’t find the function?

No I found the function but I always get 0.

The problem is that the pov that I’ve got does not fit exactly the Sketchup one (the field seems to be a bit smaller on my software). So I started to think that the fov should be corrected according to the aspect ratio…


Is it normal to get a scenes count (with SUModelGetNumScenes), that do not correspond to the scene count I’ve get with SUModelGetScenes ?

That was related to the Advanced Camera Tools extension - is that what you are looking for here?

No… As I said previously, I’m a bit confused.


Right, yes - the docs could be clearer in that respect.

What functions are you currently extracting from the SU cameras to create your own? (sample snippet?)

Hmm… that sounds odd. Got a sample model and snippet?


I use SUCameraGetPerspectiveFrustumFOV
I’ve often got 35°.
I interpret this fov as the horizontal one.

Here’s the code :

  size_t sceneMaxSize, sceneCount = 0;
  SUModelGetNumScenes(model, &sceneMaxSize);
  if (sceneMaxSize > 0)
    SUSceneRef *scenes = (SUSceneRef*)malloc(sizeof(SUSceneRef) * sceneMaxSize);
    SUModelGetScenes(model, sceneMaxSize, scenes, &sceneCount);
    for (size_t i = 0; i < sceneCount; i++)
      bool use_camera;
      SUSceneGetUseCamera(scenes[i], &use_camera);
      if (use_camera)
      { ...

And a model (from the 3D warehouse) where sceneMaxSize == 18 and sceneCount == 0 : Community-Center-Project-(Model-06).skp.zip


Hm… I need to look into what the C API return. With the Ruby API this is somewhat undefined. SU use vertical FOV normally. However, once aspect ratio is set it suddenly changes to horizontal. In SU2015 we added the fov_is_height? method to query this. Prior to this one had to make assumptions.

I’m somewhat new to the C API myself so I need to dig into the source for what it does.


This isn’t correctly initializing the SUSceneRef. If you check the result values of SUModelGetScenes you will notice you get errors:

Here’s a simple way to initialize a set of SU*Refs:

size_t num_scenes = 0;
SUModelGetNumScenes(model, &num_scenes);

size_t returned_scenes = 0;
std::vector<SUSceneRef> scenes(num_scenes, SU_INVALID);
SUModelGetScenes(model, num_scenes, &scenes[0], &returned_scenes);


Ho… I see ! Thank you tt_su… I’ll try that…


OK it works fine now !