Load and/or Save a SKM file to/from a model in Ruby
-
I asked this same question about 5 years ago but didn't find a solution:
http://sketchucation.com/forums/viewtopic.php?f=180&t=9598&hilit=material#p60141
But maybe things have changed since then.
Has anyone done anything to work with SKM materials directly from Ruby.
In particular - saving a material from the current model, or loading a material into the current model?
-
Got to the Code Snippets Index (by Author)
... and look under TIG
-
Thanks Dan (and TIG).
We will give this a try.
Al
-
The main issue is there is no simple 'zip' toolset within Ruby.
My SKMtools use small single action 'jar' files to manipulate ZIP files [aka SKM] and also the related SKM Image files, so it will work cross platform. But of course the user needs to have Java installed and .jar files set to execute in that app, and not open in say WinZip!If you are just [re]zipping/unzipping SKM files then you can of course use two separate ways - for PC [via a temporary VBS written for each occasion] and for MAC [via a similar terminal shell-script, including some applescript] [Linux is similar but misses the osa part off] - which ca provide you with the desired zip/unzip methods - I use this approach in some more recent bespoke custom toolsets [but unfortunately these are subject to NDA and (c) and all within RBS ]...
-
TIG,
I see that the SKM stuff tries to store its temporary files in the install folder (typically the Plugins folder.)
Have you had any problems with Windows 8, etc. which make it harder and harder for Apps to write to Program Files.
-
Yes, if I were to do it again today I'd make a plugin-specific subfolder in the ENV['TEMP'] folder [or OS equivalent] and then use that.
My newer tools do that, if the user sets the Plugins folder Properties > Security > Edit to FULL Read/Write and lets it affect the contents too it works OK as it is... but a more robust solution using 'Temp'/'T' folders is a good idea if you are recreating the tool's functionalities from scratch...These tools are long over due an overhaul... I might look at fixing them when I have a free slot...
-
TIG
We were able to use the import and export stuff from SKM for our Material Schemes project.
We really appreciated the saving and loading of attributes, since the last time we checked (years ago), SketchUp was not reloading attributes properly when you save a material library and then placed the material in another library.
Material Names
Another relatively simple, but important change we made was to be able to import a material, specifying a name, and have it overwrite the material with that name if it already existed. The "secret" to this was to "escape" special characters in the material name with %XX, (the hex equivalent or the character), rather than replacing them all with underscore. Then we are able to determine the original name of the material in the model from the name of the saved .SKM file.
So a library material with a name like [Stone_Masonry_Multi] is saved into a SKM file with the name: %5BStone_Masonry_Multi%5D.skm, and we can then "unescape" the name back to [Stone_Masonry_Multi] when we import it.
Material Schemes
The whole idea of material schemes is to save .SKM files for all the materials in your model into a ZIP file (e.g. Light-Blue.scheme), then to modify the materials without changing the names, save another scheme and be able to load either scheme back into the model or into other models.
-
'Collection' ZIPs...
Presumably you can use the /zip/unzip/ jar files with suitably formed ini files to do this for you?
They will work with ZIP/RBZ/SKM/Style etc -
The zip JAR's weren't working on one of my machines - either because Java is not installed - or because the JAR extension is being grabbed be Firefox.
We decided to include 7zip instead and use it for zip.
-
That's a work around if Java's not available...
Sometimes decompression tools also hijack .JAR extensions !If you are using PC only you can use VBS with 'unzip' etc...
Advertisement