Get active model return no data!

SUModelRef model;
SUResult rslt = SUApplicationGetActiveModel(&model);

rslt returns SU_ERROR_NO_DATA even tho I have loaded a model. What am I doing wrong?

For general reader information, SUApplicationGetActiveModel() is exported by the SketchUp application ONLY for use with a “live” model object, for writing “live” SketchUp exporters and rendering extensions.

It cannot be used by 3rd party applications for importers or exporters to and/or from these 3rd party applications.

That said, the C API is not yet fully “live” capable. A “live” model object must not be modified with the C API at this time. (Instead a C extension would need to make Ruby calls from the C side.)

oh! but they have dropped c++ api and COM in 19.2 and can only use the C API now so how are we suppose to pass the SUModelRef to all the functions if we can’t even get it set in the first place??

Have you generally followed the pattern shown in the GitHub example ?

  1. You should be building a .so file, that defines a main function prefixed "Init_" with the remainder of the name the exact same as the .so file’s filename. This is a requirement so that Ruby’s global #require can load the file. (See the example above, or the book on writing Ruby C extensions.)

  2. You need to be linking to the correct lib for running inside “live” SketchUp application.
    Please read @thomthom’s post re this in the following topic …
    Best practice to support multiple SketchUp versions? - #15 by tt_su

  1. That’s exactly what I do, my plugin works in 2019 and less but not in 2019.2 since I still use the c++ api.

  2. All the functions are defined for the SketchupApi.dll so are you saying that SUApplicationGetActiveModel from SketchupApi.dll is not live? So i have to define it in Sketchup.exe as if it’s a dll??

You need to convert to using the C API. The old C++ API has been removed. It has been deprecated for at least 6 years and the SketchUp team has been warning that it would be removed. (Ie, I don’t have any pity for “foot draggers” that have waited this long.)

Meaning, that with 19.2+ you cannot use any C++ API calls.

NO, you link against "sketchup.lib" for a live extension. (Reread what Thomas wrote.)
You do not link against a DLL for an extension that runs within the SketchUp application process.

I said specifically that SUApplicationGetActiveModel() is exported by the sketchup application ONLY. (This is why it is defined in "application.h".)

1 Like

I got it, working now. Thanks for your help and sorry for the bother.

1 Like

No apologies necessary. It is known that the live C API use is greatly in need of better documentation and examples. Even the examples within the SDK package need updating. (If you have any suggestions file issues in the official issue tracker.)

1 Like

Yes it does need a better documentation. I’m trying to use SUShadowInfo… but I have to pass a SUShadowInfoRef which I have no yet found out how to set it in the first place. Frustrating for sure.

If you start a thread showing what you have so far we’ll help out.

As for the live C API, apart from providing better documentation, we’re also working on a fix to sketchup.lib which is currently missing some symbols. (Just something to beware of.)

1 Like