Ruby access to styles.
-
Does anyone know if you can create styles in Ruby?
In particular, I want to use ruby to add a background image to a model.
Al
@thomthom said:
@al hart said:
(And, of course, I am assuming I can place background image into the current style using ruby. Has anyone tried this already?)
This is a good question... I'm not really sure how. I wanted to do something with watermarks via ruby a little bit ago - but I couldn't immediately figure out how. And I never got around to investigate further...
-
The API has no methods to 'create' a Style from scratch http://code.google.com/apis/sketchup/docs/ourdoc/styles.html BUT you can add a style from premade .style files [which could be shipped with your tool[s]], you can then set the desired Style current etc... You simply make your style and export it to a '.style' format within the SKP or directly using the StyleMaker tool...
You could use a method similar to my SKM-tools to manipulate or create the contents of a new 'style' file 'on-the-fly' and 'add' it... however, there are xml files and a res folder of images, including any background etc. A .style file is only a .zip file with a different suffix... However it is a complex task to read /write the required parts for a .SKM and I think a .STYLE is even more complicated. Adding a premade one is MUCH easier -
Thanks TIG.
I think that is the hint I was looking for.
I may be able to create a style with a background image, and then modify the background image and the .XML referring to it as a "ZIP" file and the reload the altered style..
<n0;screenimages> <n0;screenimage alphaScale="1" background="1" info_filename="C;\docs\blue sky sailboat.jpg" info_found="13" info_time="0" intensForAlpha="0" maintainAR="1" name="Watermark1" position="4" scale="0.3826606875934" stretched="1" tiled="0"> <n0;images>
I don't see any way for to save the current style from ruby, (Perhaps someone has found a send_action code to do that, or it can be reversed engineered somehow.) So to create a ruby to alter the background of the current style, the user may have to save the style somewhere.
But at least this gives me some hope.
-
There is no API way to save a loaded Style externally.
I managed to make a new 'material.export_SKM(folder)' method that constructs the required SKM file from bits constructed from all of the material's properties/texture etc accessed through the API, BUT that is possible because you can at least access those with the API - you can't get a fraction of the info you need from a loaded Style through the API to try and make the parts to assemble into the required .style file
There are no send_actions that would help either... -
@al hart said:
I don't see any way for to save the current style from ruby, (Perhaps someone has found a send_action code to do that, or it can be reversed engineered somehow.)
Are you consinering a cross-platform plugin, or PC only ??
-
@dan rathbun said:
Are you considering a cross-platform plugin, or PC only ??
PC only at first.
We want to write a routine to take a 360 degree spherical panoramic HDRi image and convert to a background image to match the current SketchUp screen size and perspective camera view.
We can just make the image available to the SketchUp user to place as a background image. However, if the user can give us the name of a saved style, we would like to update and reload the style automatically, so that when the view is changed it will just take one click (or perhaps an "observer") to update the background image.
-
@al hart said:
We want to write a routine to take a 360 degree spherical panoramic HDRi image ...
These HDRi images are spherical? or cylindrical?
-
Advertisement