Copy link to clipboard
Copied
Hi,
I work at a CGI Studio and we use Bridge to acess and manage our library of textures etc.
Now textures usually consist of several seperate image files, let's say three (_DIFFUSE, _BUMP, _SPECULAR)
The filename of these three files, say they're from a wood material, would always be like "Wood-"+counter+"_DIFFUSE", example: "Wood-003_DIFFUSE.jpg", "Wood-003_BUMP.jpg" and "Wood-003_SPECULAR.jpg"
Now I manually grouped the three seperate image files together so I have a stack of three. The thing is we got hundreds of those 3-file-images.
Basically I need a way to automatically stack all the images which have the same beginning/pattern
Related: I did this once manually but for some reason Bridge messed up after a few days and got them all half-ass together and jumbled them around resulting in all files still being there but not properly stacked anymore...
Now I know my way around proprietary scripting languages and am familiar with stuff in general. Do I need to do scripting here or is there a better way to do so?
How would I start? Where? Has anyone links to a solution for this (I think common) problem?
Copy link to clipboard
Copied
Here is one solution.
#target bridge
if( BridgeTalk.appName == "bridge" ) {
woodStack = MenuElement.create("command", "Wood Stack", "at the end of submenu/Stack");
}
woodStack.onSelect = function () {
var fileList = Folder(app.document.presentationPath).getFiles("*diffuse*");
for(var a in fileList){
var firstFile = decodeURI(fileList.name.match(/[^_]*/));
var filesToStack = Folder(app.document.presentationPath).getFiles("*"+firstFile+"*");
if(filesToStack.length == 3) {
app.document.deselectAll();
for(var s in filesToStack){
app.document.select(new Thumbnail(filesToStack
));}
app.document.chooseMenuItem("StackGroup");
}
}
};
Copy and paste the script into ExtendScript Toolkit or a PLAIN TEXT editor.
Then save it out as filename.jsx
The correct folder to save the script can be found by opening Bridge, going to the preferences - Startup Scripts and clicking on the "Reveal my startup scripts" button.
Once saved close and re-start Bridge.
To use, selected the folder you want to stack the groups of files and select Stacks - Wood Stack
Copy link to clipboard
Copied
Hey, that's really nice!
I'll have to dig through the code to see what's happening there. As I didn't expect a complete solution I might have given some too abstract/incomplete information.
Since I cannot edit the original Post, I will try to make my point here:
I have a folder X in which there are n files. The files are not strictly image file formats, also others (*.max for example, shouldn't matter).
The files are named after the following sceme: [Prefix]-[3-padded Number]_[Suffix], Examples: Wood-003_DIFFUSE, Metal-112_SPECULAR
Basically I need to collect all n files (no matter the type) in that folder x which have the same Prefix+Number, so one group could be:
(Metal-010.max, Metal-010_DIFFUSE_v1.jpg, Metal-010_DIFFUSE_v2.jpg, Metal-010_SPECULAR.jpg, Metal-010_BUMP.jpg), and in that same folder x there would be other files like Wood-115_DIFFUSE.....
So I need an approach where the only criteria is basically the Prefix and the Number for grouping, which I think may make things easier?
Copy link to clipboard
Copied
It should still work as this line..
var firstFile = decodeURI(fileList.name.match(/[^_]*/));
gets the first part of the filename upto the first underscore, and uses this to get the other files.