# Setting the watermark with Ruby

**URL:** <https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864>\
**Category:** Ruby API\
**Tags:** styles, ruby, extension, watermark\
**Created:** [September 19, 2017, 4:27pm UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864 "2017-09-19T16:27:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![retrev](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/retrev/32/37905_2.png) [@retrev](https://forums.sketchup.com/u/retrev)\
**Post date:** [September 19, 2017, 4:27pm UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/1 "2017-09-19T16:27:25Z")

</div>

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.

```auto
> 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?

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [September 19, 2017, 6:18pm UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/2 "2017-09-19T18:18:12Z")

</div>

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](http://ruby.sketchup.com/Sketchup/Styles.html#add_style-instance_method)

```
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…  
.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 20, 2017, 12:19am UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/3 "2017-09-20T00:19:36Z")

</div>

… and, **`Sketchup::active_model.rendering_options["DisplayWatermarks"]`**  
must be set **`true`** (which is a style setting.)

Or, … it can be toggled on (or off) via code:

```ruby
Sketchup::active_model.rendering_options["DisplayWatermarks"]= true

```

* * *

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.

---

<div class="post-metadata">

**Author:** ![retrev](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/retrev/32/37905_2.png) [@retrev](https://forums.sketchup.com/u/retrev)\
**Post date:** [September 21, 2017, 2:20am UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/4 "2017-09-21T02:20:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![retrev](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/retrev/32/37905_2.png) [@retrev](https://forums.sketchup.com/u/retrev)\
**Post date:** [September 21, 2017, 2:21am UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/5 "2017-09-21T02:21:26Z")

</div>

I manually load a watermark then save the style and unzip it. None of the files (an icon png and some xml) seem to reference the watermark anywhere.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 21, 2017, 3:32am UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/6 "2017-09-21T03:32:06Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![colin](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/colin/32/70101_2.png) [@colin](https://forums.sketchup.com/u/colin)\
**Post date:** [September 21, 2017, 4:06am UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/7 "2017-09-21T04:06:08Z")

</div>

I just tried too, and there isn’t a ref subfolder. Not even an invisible one. And no mention of a png in any of the three XML files.

---

<div class="post-metadata">

**Author:** ![retrev](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/retrev/32/37905_2.png) [@retrev](https://forums.sketchup.com/u/retrev)\
**Post date:** [September 21, 2017, 2:18pm UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/8 "2017-09-21T14:18:43Z")

</div>

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:

```ruby
def import_result
    sname = File.dirname( __FILE__ )+"/MyStyle.style"
     `cp "#{sname}" "#{Sketchup.temp_dir}"`
     zname = Sketchup.temp_dir+"/MyStyle.style"
     zf = Zip::File.open(zname)
     zf.add("ref/output.png", @result_path.path)
     zf.close
     Sketchup.active_model.styles.add_style(zname, true)
     Sketchup.active_model.styles.purge_unused
end

```

Attached is the style I used. (modified from the 3D printing default)  
[MyStyle.style](https://forums.sketchup.com/uploads/short-url/9ckSExRJWOKcueGGomVt6N9DQlT.style) (4.2 KB)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 22, 2017, 1:55am UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/9 "2017-09-22T01:55:32Z")

</div>

> [@retrev](#):
>
> 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).

Yup, as I asked:

> [@DanRathbun](#):
>
> Did you update the style after applying the watermark, and before saving it ?

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.

Glad you got the workaround working.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [December 22, 2017, 5:58pm UTC](https://forums.sketchup.com/t/setting-the-watermark-with-ruby/51864/10 "2017-12-22T17:58:30Z")

</div>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.
