Ruby code to extract watermark
-
Does anyone know how how to get the watermark image in the ruby console? The API shows how to get the active_style and such, but no reference to the watermark!
Thanks for any advice you can provide.
-
There doesn't seem to be any get/set methods for watermarks...
-
But there is a 'WatermarkManager', perhaps undocumented?
-
@alienizer said:
But there is a 'WatermarkManager', perhaps undocumented?
Where have you found this?
I don't find it anywhere in the Ruby API...
-
@thomthom said:
Where have you found this?
I don't find it anywhere in the Ruby API...In Sketchup.exe there is the word 'WatermarkManager' (no space) so it must mean something oter than plain English 'Watermark Manager'.
-
There might very well be something like that in SketchUp - but not something that's exposed to the Ruby API. There are some bits and bobs missing.
-
@thomthom said:
There might very well be something like that in SketchUp - but not something that's exposed to the Ruby API. There are some bits and bobs missing.
Maybe it's just an undocumented api?
-
It's not an API if it's not available. I can't find it even in the C++ SDK for reading and writing SketchUp files.
-
'WatermarkManager' appears in these files
-
The only solution I see would be to scan the .skp for image header info.
See this post for example code.
-
@thomthom said:
There doesn't seem to be any get/set methods for watermarks...
I was hoping I could find something here on the forum on how access watermarks (set at least).
I guess it can be done through C Extension... I appreciate a help from Google team. -
@unknownuser said:
@thomthom said:
There doesn't seem to be any get/set methods for watermarks...
I was hoping I could find something here on the forum on how access watermarks (set at least).
I guess it can be done through C Extension... I appreciate a help from Google team.C Extensions can't do anything more than normal Ruby. It still needs to deal with the Ruby API.
The C++ SDK might, but that is for reading and writing .skp files - not dealing with the currently open model in SU.
-
In the same way that my SKMtools add some missing API functions to let you load a SKM file as a Material, save a Material as a SKM file, or extract SKM images/thumbnails etc, you COULD envisage a similar StyleTools set of additional methods. A '.style' file is only a zip-file with a different suffix - any watermarks are defined in the 'document.xml' under the 'screenimages' section as an individual 'screemimage' with its settings and the required image file is in the 'ref' folder. So if you just want to get a watermark image from a .style file it's straightforward - but getting any info from a loaded Style is fraught... Unfortunately, whilst the making/setting/adding .style parts seem quite possible, access to loaded Style info is very limited - to name and description !
You could envisage a tool that compiles the required parts of a 'zipped' style [images and xml files] into a new .style file that you then load into the SKP using standard API methods...
Here's an extract of some watermark xml<span class="syntaxdefault"></span><span class="syntaxkeyword"><</span><span class="syntaxdefault">sty</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">item id</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"5001"</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault">t</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">variant type</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"13"</span><span class="syntaxdefault"> xmlns</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"http://sketchup.google.com/schemas/sketchup/1.0/wmlist"</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">wmlist count</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"2"</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">screenimages</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">screenimage name</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"&lt;MODEL SPACE&gt;"</span><span class="syntaxkeyword">/><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">screenimage alphaScale</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0.81"</span><span class="syntaxdefault"> background</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0"</span><span class="syntaxdefault"> info_filename</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"C;\Aagard\Library\Components\AagardLogo.png"</span><span class="syntaxdefault"> info_found</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"1"</span><span class="syntaxdefault"> info_time</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0"</span><span class="syntaxdefault"> intensForAlpha</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0"</span><span class="syntaxdefault"> maintainAR</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"1"</span><span class="syntaxdefault"> name</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"AagardLogo"</span><span class="syntaxdefault"> position</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"2"</span><span class="syntaxdefault"> scale</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0.12"</span><span class="syntaxdefault"> stretched</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0"</span><span class="syntaxdefault"> tiled</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0"</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">images</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">image id</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"1"</span><span class="syntaxdefault"> path</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"AagardLogo_1.png"</span><span class="syntaxkeyword">/><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"></</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">images</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"></</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">screenimage</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"></</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">screenimages</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"></</span><span class="syntaxdefault">n0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">wmlist</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"></</span><span class="syntaxdefault">t</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">variant</span><span class="syntaxkeyword">><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword"></</span><span class="syntaxdefault">sty</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">item</span><span class="syntaxkeyword">></span><span class="syntaxdefault"> </span>
and the .style file's contents...
-
@thomthom said:
C Extensions can't do anything more than normal Ruby. It still needs to deal with the Ruby API.
I am aware of it. I thought one could access certain C methods within SU Dll's/internals to set a watermark.
-
You can actually display watermarks.
model = Sketchup.active_model opts = model.rendering_options opts['DisplayWatermarks'] = true/false
Yep, there is no function to get/set watermark image, though there is actually a way around it.
"Watermarks are part of a Style. You would have to have a preset Style with the watermark, and change the Style with the API." - quote by Dan.
Create a style or two, add watermarks to each, and set them via Ruby API:
styles = Sketchup.active_model.styles styles.selected_style = styles['Style Name'/style index#]
Reference: Watermark via Ruby API
Advertisement