Cannot load *.style using SDK

Hello everyone,

Glad to have joined these forums, SketchUp is an amazing tool and we’re using the SDK to build a huge free-to-use material/object library for everyone to enjoy. We’re featured on the 3D Warehouse page under Rockit3D!

So in our library, I want to use the SDK to put watermark images on every SketchUp file, basically with pre-rendered graphics to show what a material will be like rendered.

Example:

It will look like this, right now I did it all by hand…

To accomplish this, I want to use the SDK to import a *.style file and set it as active.

I’ve tried many things but the SDK simply won’t handle it… when I open this exact *.style file inside SketchUp 2019 Pro it works perfectly.

const char *path = "C:\\Users\\phant\\Desktop\\work4\\Rockit3DStyle.style";
			
			SUResult result;

			SUStylesRef styles = SU_INVALID;
			result = SUModelGetStyles(model, &styles);
			if (result == SU_ERROR_NONE) { std::cout << "success" << std::endl; }
			if (result == SU_ERROR_INVALID_INPUT) { std::cout << "model is not a valid object" << std::endl; }
			if (result == SU_ERROR_NULL_POINTER_INPUT) { std::cout << "manager is NULL" << std::endl; }

			
			SUStyleRef style = SU_INVALID;
			result = SUStyleCreateFromFile(&style, path);
			if (result == SU_ERROR_NONE) { std::cout << "success" << std::endl; }
			if (result == SU_ERROR_NULL_POINTER_INPUT) { std::cout << "style is null" << std::endl; }
			if (result == SU_ERROR_INVALID_INPUT) { std::cout << "*style does not refer to a valid object" << std::endl; }
			if (result == SU_ERROR_NULL_POINTER_INPUT) { std::cout << "path is NULL" << std::endl; }
			if (result == SU_ERROR_SERIALIZATION) { std::cout << "style couldn't be created from the file at path" << std::endl; }
			
			result = SUStylesAddStyle(styles, path, true);
			if (result == SU_ERROR_NONE) { std::cout << "success" << std::endl; }
			if (result == SU_ERROR_INVALID_INPUT) { std::cout << "styles is not a valid object" << std::endl; }
			if (result == SU_ERROR_NULL_POINTER_INPUT) { std::cout << "name is NULL" << std::endl; }
			if (result == SU_ERROR_DUPLICATE) { std::cout << "the name corresponds to an existing style" << std::endl; }

This prints out:
-success
-style couldn’t be created from the file at path
-the name corresponds to an existing style

I don’t get why it doesn’t work. Again, importing the same *.style file into SketchUp works perfectly.

I know the code isn’t pretty. Let’s please just get it to work first.

We’re using the latest SDK: SDK_WIN_x64_2019-0-753_0

Our problem is similar to this, which was never answered:

Thank you!

Best,

Guus

Hi Guus

Adding a new style to a model doesn’t make it the selected/active style. Unfortunately that function is missing from the C API - but it’s on our list.

1 Like

Thanks for the reply, so is there any way at all to set an image as watermark through the C API?

Apart from setting as the active style, right now it doesn’t seem possible to import a *.style file without it erroring.

Another option I found is function SUStylesApplyStyleToScene which can set a style active right? We can setup a single scene in each file and then apply this. But first the style needs to be accepted in… is there some kind of example where it’s proven that style importing works? That would help a lot!

  • Before you get mired in the ruts of trying to add a style, what are you wishing to achieve for the enduser ?
  1. Generally, adding images to components bloats them (sizewise) and user’s models, … which user will not like. I see this as a negative which would preclude users from using your object libraries.

  2. Watermarks in components would not trigger watermarks in the user’s model being switched on, as it’s a style setting of whatever style(s) the user has their model and / or scenes set to use.
    Changing any style settings in what the user has set, is likely to upset the professional user greatly.

  3. In a quick test, I do not see an embedded style in a SKP component being imported into a user model via File > Import…, nor the Components browser inspector panel.

So I’m thinking perhaps using styles isn’t going to work anyway.

Perhaps setting the thumbnail image is more appropriate ?
This is what would appear as the 3D Warehouse thumbnail image, would it not?

Adding a preview watermark only adds 30 kB which is neglelible.

We’re also adding in a bunch of images for our ‘indicator’ components, since SketchUp is at the moment problematic which detailed geometry, so we swap out those components for render-grade models in our rendering system. Our software is rigged to detect our resources.

Importing a material/object through component browser or copying over the resource into the working model does not copy along any style settings. Through the component browser the watermark doesn’t come along so that’s no problem.

The style settings are definately embedded somehow because it works when I add watermarks in by hand, check our or plants: https://3dwarehouse.sketchup.com/collection/e2048236-e2f4-49ad-bc37-4606bad6cf7e/ROCKIT3D-Vegetation
Also on our cars: https://3dwarehouse.sketchup.com/collection/38be9140-f15e-4d76-aa96-55d1c9ef76d1/ROCKIT3D-Cars

Indeed I would prefer the thumbnail, but the content manager doesn’t allow us to do so, that only works for collections and not actual resources.

We might choose not to do the watermarks since we have it featured on our website’s catalogue page:https://catalog.rockit3d.com/

But it does look a lot worse in 3D warehouse without proper thumbnails of what it will be like.

Please let me explain our workflow better, this ties into the desire for preview images.

Here is our designed workflow: https://rockit3d.com/how-to-use/

Basically we’re building an AI platform that can automatically make renders for users, from base SketchUp, with models/materials from our library for the best results. We believe in a future where AI assists designers and don’t have to deal with any of the technical stuff. A lot of people love designing but hate the visualising process.

From base SketchUp model:

Straight to render, fully automatic (user selected sky setting and sun angle):

(Working model for this render has some slight adjustments)

I guess this topic has now kind of turned into a design topic regarding the use of watermarks

I looked at your Acer plamatum. I do not see any watermark either in a model it is inserted into, nor in the component file itself.

I see a component wrapper, that contains an image, a hidden group and a tree component.

Then how does 3D Warehouse show the 3D watermark image I added?

Did you add the image via the Watermark panel of the Edit page in the Style inspector, or just insert the image into the component in the background ?

I defer to @Barry in regard to the 3DW. Perhaps it now uses watermarks instead of thumbnails when present? (just guessing)

1 Like

Thank you, yes it was added using the Watermark panel in the style inspector.

Say we have a SketchUp file with 2 scenes in it.

Scene 1 - here is where we want to load in a style so it displays the watermark (the watermark previews what the material/component looks like when rendered).

Scene 2 - no style, here the user sees the model.

How to accomplish this?

I’ve uploaded our exact use-case, please have a look:

First scene shows style with watermark, second scene shows material that people can draw with inside SketchUp. When getting this through the Component Browser, it immediately gets the geometry and does not get the style, which is exactly what we want. And yet it does show this material preview thumbnail which is even more perfect!

But to repeat the problem, the function in the SDK to get a style in doesn’t seem to work, please see earlier posts.

Thank you!

Oh - I missed this.

I also just realized that SUStylesAddStyle had a activate parameter that should set it as active.

I need to look closer at this.

1 Like