Batch replace all textures in model with in one script?
-
I'm hoping one of you fine folks is able or willing to advise me on a SketchUp script that I am convinced would be extremely helpful in lots of people's workflows.
Let's say I have applied a series of unique artworks to a model. Let's say I have 20 unique JPG artworks with 20 unique filenames placed in my model. That would amount to a list of files (artwork1.jpg, artwork2.jpg, artwork3.jpg...etc).
Now... let's say that I have updated JPGs -- the same exact list, but the artwork has been modified in some way, and I need to update my model with each of them.
Currently, the only way to do this is to painstakingly replace each and every texture instance one by one in the material editor.
SURELY THERE IS A BETTER WAY??
https://forums.sketchup.com/t/batch-create-materials-from-directory-of-files/114300
Looks like this person was on to something. Is there anyone here who could help me rewrite this Ruby script (I'm new to Ruby, so bear with me) in such a way that we could batch replace every texture in the model with its corresponding JPG? In other words, a single script that would look in a specific folder, and replace any texture in my material library with the JPG in the folder whose name matches that texture?
I refuse to believe this is impossible. Can anyone help?
-
Let's assume the
model.materials
are 'inspected' and only those with associated textures are put into a 'list' - let's call that -mats
and now we process that...
Next. in turn look at each material and get its texture, and its path
textu = mat.texture filen = textu.filename
Check the path given in filen against a list of possible jpg names...
Assemble that list from the contents of some subfolder you've set up and defined...
There are Ruby tools to compare just the file-names [File.basename etc] and also to allow for non-matching cases etc...
Assuming that you now have a match, then you have the new file path -filenew
So use
mat.texture = filenew
That material now is assigned the replacement textu[tr] ?? -
@tig said:
Let's assume the
model.materials
are 'inspected' and only those with associated textures are put into a 'list' - let's call that -mats
and now we process that...
Next. in turn look at each material and get its texture, and its path
textu = mat.texture filen = textu.filename
Check the path given in filen against a list of possible jpg names...
Assemble that list from the contents of some subfolder you've set up and defined...
There are Ruby tools to compare just the file-names [File.basename etc] and also to allow for non-matching cases etc...
Assuming that you now have a match, then you have the new file path -filenew
So use
mat.texture = filenew
That material now is assigned the replacement textu[tr] ??I thought the textures were embedded in the SKP file itself. When textures are placed, they don't appear to live at any particular filepath. That's the part that confuses me about how SketchUp works.
-
When you make a new material and then give it a texture, the method mat.texture.filename return that texture's file-path, or in the case of an 'orphaned texture' - just its 'image-name' - e.g. from the SKM library where no path is applicable...
You are muddling materials and textures.
Just process a few materials and list if they have textures and then the texture's filename...
-
@tig said:
When you make a new material and then give it a texture, the method mat.texture.filename return that texture's file-path, or in the case of an 'orphaned texture' - just its 'image-name' - e.g. from the SKM library where no path is applicable...
You are muddling materials and textures.
Just process a few materials and list if they have textures and then the texture's filename...
Sorry...I don't mean texture as in bump map. I mean literally a JPG image, brought into a model and applied to a surface. What would that be called?
-
An image used as part of a material is called a 'texture'.
There's no bump-maps inside SketchUp.
So any image like a JPG or PNG is called a 'texture' when associated with a SketchUp material...
Advertisement