Getting screen aspect ratio in SDK?

So one of the return types of SUCameraGetAspectRatio() is

SU_ERROR_NO_DATA if the camera uses the screen aspect ratio

So how can I get the screen aspect ratio? I’m trying to export out the cameras that the user is seeing currently in their document, so I’d like to at least start with that aspect ratio in the exported file.

I wonder whether the documentation actually means the viewport aspect ratio instead of the screen aspect ratio.

If a camera has no aspect ratio set, it is maybe intended to use just whatever aspect ratio the viewing application has, no matter whether that is SketchUp, or another application.

In the Ruby API, you would get it from Sketchup::View#vpwidth / #vpheight, but I didn’t find a corresponding method on the SDK side. The SDK is focussed on importing/exporting (eg. .skp writers without SketchUp running) and does not expose all methods that one would use for writing a tool that interacts with the viewport.
When SketchUp is running, you can access SketchUp’s Ruby API through a Ruby C extension, but I don’t know if/how that can be integrated in combination with using the SDK.

Yea, I expect they mean the aspect ratio of the current view in the window. I still would love to get it.

I’d think you would need to include the ruby headers, then:


  double aspect_ratio;
  rbFloat = rb_eval_string("Sketchup.active_model.active_view.vpwidth.to_f / Sketchup.active_model.active_view.vpheight.to_f");
  aspect_ratio = NUM2DBL(rbFloat);

can you get the 2D export dimensions via the sdk? they’re the same as the viewport (‘use view size’)

(lost in the developers forum again ;) )

I’m afraid it’s not - it’s similar to the Ruby API where the aspect ratio will return 0.0 if there is no custom aspect ratio - in which case the viewport aspect ratio is used. In the C API NO_DATA is returned.

From the comments:

// In SketchUp object model, a camera may have an aspect ratio of 0 which
// means that the aspect ratio of the window is used.  SLAPI doesn't have
// access to the view, so we will return SU_ERROR_NO_DATA in that case.

It’s one of the areas where the C API needs improvements.

That would only work if you where creating a Ruby C Extension - not a standalone application.