SKM files
-
OK, I know there are some older posts out there, so this is a long shot...Is there a way to load SKM files and add them to the Sketchup.active_model.materials collection? I have tried some of the obvious methods, but have not had luck. I am trying to save some attributes in an attribute library attached to the material. I can see that the attribute library is saved in the skm file (changed it to zip and looked at the xml). It also reloads the attributes correctly when I use it from the material window - so it basically works. I would like to apply the materials to some of the object using ruby...
Jon
-
Nope - via the Ruby API we are unable to Read/Write .skm files.
-
If you use convoluted zip commands not available in SUp Ruby but available in the broader Ruby world... then you can read/write external SKM files - but awfully complicated.
If you want to load materials from known external SKM files there is a 'trick'.
Make a SKP file with just one face in it divided into several parts and apply the required materials to each part in turn.
Those Materials are added to that SKP'smodel.materials
list
Purge the Model.
Erase all of the face/facets so the SKP is now empty, save for the now unusedmodel.materials
.
Add a cpoint [or any small geometry] at the origin [this is because you can't import an empty SKP later on]
Save/close the SKP as 'MyMaterialsToImport.skp' - or whatever name you fancy.
Now whenever you want to load your Materials you use something like this...
model.start_operation("Import Materials") defs=model.definitions.to_a model.import(path_to_MyMaterialsToImport.skp) defn=(model.definitions.to_a - defs)[0] defn.entities.erase_entities(defn.entities.to_a) model.commit_operation
The start/commit is needed to remove the emptied temporarily imported SKP/Compo defn from the Browser and tidy up.
The materials are now available in themodel.materials
list for use...The above method batch imports Materials BUT of course you could make one SKP named after each SKM with just that material in it and then import them individually as needed...
If you often use materials you can of course add them to your SKP templates as first described above - erasing temporary faces etc [my Templates do indeed already have several empty Layers, two Styles and a few commonly required Materials already in them so at startup you don't need to make or to load them from outside sources]
-
Thanks for the good information. Has anyone submitted an enhancement request to Google for some SKM read/write api?
Jon
-
Yea, but keep nagging them.
-
I'm currently looking at a cross-platform way of reading/writing skm's using a Java app, and a cmd/terminal files [for PC/MAC] - I already use something similar in the Octane Render exporter that needs to run that exe with arguments on all platforms.
I know I can extract images [and thumbnails], and get the xml contents, to clone the skm into the skp, but I need to get it working less clunkyly - without user input...
If I ever get anywhere near so solution I'll post something.It would just be easier it they built it in but I suspect that Google have other fish to fry...
-
Um...What program uses an SKM file?
-
SketchUp!
-
@3eighty said:
Um...What program uses an SKM file?
It's a SKetchup-Material file - didn't you ever look in your Materials folder
-
Just wanted to be sure you guys were alert.....
Advertisement