I’m using a watermark as a method of display for an external rendering tool. (export collada model, render, import resulting file as a watermark background) I’m trying to automate the process via an extension but I can’t figure out how to set the watermark.
> s = Sketchup.active_model.styles.first
> s.attribute_dictionaries.nil?
true
I don’t see any useful methods on s, just name and description. I figured this might be set via attributes but it appears there are none on the object. What am I doing wrong?
Make the Style you want - including its watermark.
Save it externally as a .style file.
Ship that file with your extension - in its subfolder.
Now use the method to load that style and set it current… Class: Sketchup::Styles — SketchUp Ruby API Documentation
filename = full_path_to_MyStyle.style
styles = Sketchup.active_model.styles
status = styles.add_style(filename, true)
Setting the second argument to true means it becomes the active style.
It is straightforward to set the path to the style file - _FILE_ returns the loading RB file’s path, so from that you can get the subfolder+style as a string and pass it to the method…
.
There is no way to import watermark images except by a Style, and styles are not fully exposed to the API (yet.)
The .style filetype is a Zip archive with embedded XML files and subfolder with resources (ie, images, texture, etc.) The XML schemas for .style (and .skm, etc.) are not published.
That doesn’t help with my problem…the watermark image is dynamic and is updated by an external program I’m running from an extension. I then want to load the resulting image as a watermark.
I just did the same, and I have no problem seeing that the watermark image is in the "ref" subfolder (within the archive,) and that the "document.xml" file contains a reference to this file (as well as the path from where it was originally loaded from,) and all of the watermark properties for the model.
Did you update the style after applying the watermark, and before saving it ?
I figured out the problem. Adding the watermark makes it show up in the model but doesn’t actually store it in the style. There’s a button up near the style name/description to refresh the style with the changes (instead of just a preview I guess). After doing that, I save the style, unzip the .style file and document.xml has the expected entry with the image in res.
I then change the zip to remove the res file and put the .style in my extension. I have some code to do the following:
The action in SketchUp is called “updating the style” with the changes. You have the option of abandoning style changes, so that you can play around until you get what you want. Whenever you have made changes, you’ll see the little preview icon has a “needs updating” icon superimposed over it. But you can ignore that if you just tried something and did not care for the results.