Access Current viewport information from C Api?

Hi!

I’m working on a exporter using the C API and I wonder if it’s possible to get the camera information of the “viewport” (that’s it the camera being used by the user while moving around and editing the model).

I only found structs and functions for scene cameras, but that’s not really what I wanted.

Is this possible or not currently supported?

Cheers

Didn’t check but did you tried SUModelGetCamera

1 Like

Hi, yes, but it comes up null, it seems it’s only used for Scene cameras, not the viewport one

An exporter from the SketchUp process? …
Or an exporter from another application to write out a SKP file?

Perhaps this is only valid from within the SketchUp application using the C API in “live” mode when you get the model from SUApplicationGetActiveModel() ?

Or maybe, it is NULL when the model has scene pages. I.e., when a model has no scene pages, then perhaps the model itself stores a camera object.

But, there is no need for the model to store a camera, if the model has scenes, because SUModelGetActiveScene will have the edit camera.

So, first check SUModelGetNumScenes() and if 0 then get the model’s camera, if > 0, then get the active scene’s camera.


EDIT: After a night’s rest and a cup of coffee, I remembered that the scene pages can be set to not save camera position, so my musing (above) is not likely true.

Hi, did some basic tests, works as expected for both (LiveCAPI and standalone importer):
SU2025

	SUCameraRef camera_ref = SU_INVALID;
	if (SUModelGetCamera(model_ref, &camera_ref) == SU_ERROR_NONE && SUIsValid(camera_ref))
	{
		bool is_perspective = true;
		SUVector3D direction;
		double fov;

		SUCameraGetPerspective(camera_ref, &is_perspective);
		SUCameraGetDirection(camera_ref, &direction);
		SUCameraGetPerspectiveFrustumFOV(camera_ref, &fov);


		LogPrint(L"Camera is valid, persperspective(%d) fov(%0.00f) dir(%0.00f x %0.00f x %0.00f)", 
			is_perspective, fov, direction.x, direction.y, direction.z
		);
	}
	else
	{
		LogPrint(L"no camera");
	}
1 Like

thanks this worked as expected

So, what was it that prevented you from getting a valid camera?