Creating a material from an existing one
-
Is this possible?
I did not find anything in the Ruby doc about how to do that.What I have found is that:
- You can create a new material by name
- you can only assign a texture to the material by filename (it has to be a JPG)
- However, with SU v6, the JPG is not available as a file but embedded is the SKM file of the material
Thanks
Fredo
-
-
If you examine the .SKM file, you will discover that it is a zip file with the material stored in it. So if you have a way to read the zip file from Ruby, you can access it.
-
Another way we get the texture is to assign the material to a face or image and use TextureWriter to write the textures to a file. (If it is a "distorted" texture, it will not write the original texture, but rather the texture as it appears on the face.)
-
-
@al hart said:
- If you examine the .SKM file, you will discover that it is a zip file with the material stored in it. So if you have a way to read the zip file from Ruby, you can access it.
This is good to know, but it would be rather convoluted, especially for the objective I research which is just a script to put the selection in Xray, while the rest of the model is unchanged.
@al hart said:
- Another way we get the texture is to assign the material to a face or image and use TextureWriter to write the textures to a file. (If it is a "distorted" texture, it will not write the original texture, but rather the texture as it appears on the face.)
I played with the Texturewriter of course, with a Load from a face, but the method filenamedoes not even return anything!
Actually, the question is not really to get the texture, but to create a material as a clone of another one, and then change some parameters(in my case the transparency via the Alpha method). You can do all this with the User Interface of the Sketchup paint bucket, but apparently the Ruby API is far behind.
Thanks for your help.
-
Did you call tw.write(entity, fname)
-
@al hart said:
Did you call tw.write(entity, fname)
No. My intention is not to export material or even get the JPG file for the texture, but just clone a material within the model, and then change parameters of this new material.
-
We have a similar function.
The material is on a face. We use tw.write to ave the raster image to a temporary file, and then use the image to create a new material.
-
@unknownuser said:
@al hart said:
Did you call tw.write(entity, fname)
No. My intention is not to export material or even get the JPG file for the texture, but just clone a material within the model, and then change parameters of this new material.
I agree about needing to read or write on the disk in order to accomplish this; however... if you are going to be reading and writing files, why not copy the .skm, load it, and make the adjustments? Either way, it looks as if the best you are going to do is a clunky work-around.
-
@jim said:
I agree about needing to read or write on the disk in order to accomplish this; however... if you are going to be reading and writing files, why not copy the .skm, load it, and make the adjustments? Either way, it looks as if the best you are going to do is a clunky work-around.
Well, this is to create programmatically a semi-transparent material from an existing material. This is the only way to build a macro that would show part of the model in Xray (as the View mode of Sketchup applies to the whole model). At the moment, I can do it with color of material, but cannot get the textures to be Xray'ed.
See discussion thread in the forum at http://www.sketchucation.com/forums/scf/viewtopic.php?f=57&t=6638
and also in the French section (http://www.sketchucation.com/forums/scf/viewtopic.php?f=51&t=6589&start=0)
Advertisement