I think this might be possible. Can anyone help me out on this?
What I have-- Here's an example of a Layer Comp name: jody-my-2013-arty-cc-486_227x121. I have multiple layer comps with similar names except "jody" and "cc-486" are different for each Comp.
What I'd like to do is to be able to replace the numbers after the underscore with a new set of numbers. The numbers being replace will not always be 227x121, and there will be different amounts of digits. The digits below are what i will start with and/or replace with:
227x121
462x249
960x534
1024x576
1024x768
1024x1024
1280x768
1280x800
Can anyone help me with a script that says replace all of the characters after the underscore with a new set of numbers (and the "x" between them).
A script that would give me the opportunity to enter the values in a pop-up window at the start of the script (I think I'd prefer this approach), or a separate script for each set of the numbers above would be great.
Mucho thanks in advance.
Replacing suffix in Layer Comps
-
pmn
Replacing suffix in Layer Comps
Maybe a simpler approach would be better.
Can anyone help me with a script that replaces all of the characters after an underscore (the underscore would be the last character in the original name) in the name of layer comps. I assume pop-up window at the start of the script where the replacement text would be typed would be needed.
Thanks for your help.
Can anyone help me with a script that replaces all of the characters after an underscore (the underscore would be the last character in the original name) in the name of layer comps. I assume pop-up window at the start of the script where the replacement text would be typed would be needed.
Thanks for your help.
-
bdeshazer
Replacing suffix in Layer Comps
Here is a sample of one way of doing the renaming via DOM:
Code: Select allvar newsuffix="1280x800";
var comp=app.activeDocument.layerComps.getByName("jody-my-2013-arty-cc-486_227x121");
var nameparts=comp.name.split("_");
var newname=nameparts[0]+"_"+newsuffix;
comp.name=newname;
This assumes there will be only one underscore character in the layer comp name.
Code: Select allvar newsuffix="1280x800";
var comp=app.activeDocument.layerComps.getByName("jody-my-2013-arty-cc-486_227x121");
var nameparts=comp.name.split("_");
var newname=nameparts[0]+"_"+newsuffix;
comp.name=newname;
This assumes there will be only one underscore character in the layer comp name.
-
pmn
Replacing suffix in Layer Comps
thanks for the help. it works when the layer comp name is, jody-my-2013-arty-cc-486_227x12, but not for other layers with different names.
i know wasn't perfectly clear when i reached out for help. i've tried to modify the code to fit my needs but to no avail.
this is my situation:
the string, "jody-my-2013-arty-cc-486_227x121" will be different for each layer comp. for example it may read, "pat-my-2013-soup-gr-1265_1582x1234". there will be hundreds of variations. the characters and character count will be different for each layer comp. the only constant is the "_" (underscore) at the end of the string.
is there a way to replace the string, "jody-my-2013-arty-cc-486_227x121" that reflects this variable--so this string isn't a constant but a variable?
thanks again for you help.
i know wasn't perfectly clear when i reached out for help. i've tried to modify the code to fit my needs but to no avail.
this is my situation:
the string, "jody-my-2013-arty-cc-486_227x121" will be different for each layer comp. for example it may read, "pat-my-2013-soup-gr-1265_1582x1234". there will be hundreds of variations. the characters and character count will be different for each layer comp. the only constant is the "_" (underscore) at the end of the string.
is there a way to replace the string, "jody-my-2013-arty-cc-486_227x121" that reflects this variable--so this string isn't a constant but a variable?
thanks again for you help.
-
Mike Hale
Replacing suffix in Layer Comps
Will there every be more than one underscore in the name? If there is only one you can use a RegExp to match the name. But you will have to search all the layerComps and there still may be problems if the comps have similar names.
Another approach would be if the layerComp is always in the same place in the comps panel. For example it is always the second comp. Then you could reference the comp by index.
Another approach would be if the layerComp is always in the same place in the comps panel. For example it is always the second comp. Then you could reference the comp by index.
-
bdeshazer
Replacing suffix in Layer Comps
Mike Hale wrote:Will there every be more than one underscore in the name? If there is only one you can use a RegExp to match the name.
If there is only one underscore character then the example I posted using "split" should be sufficient I would think... a RegExp would be needed if more than one.
Mike Hale wrote:But you will have to search all the layerComps and there still may be problems if the comps have similar names.
Another approach would be if the layerComp is always in the same place in the comps panel. For example it is always the second comp. Then you could reference the comp by index.
Re-reading the original post it appears that OP wants a GUI for selecting the layer comp and possibly the replacement text... not really difficult but not something I have the time to do for free right now...
If there is only one underscore character then the example I posted using "split" should be sufficient I would think... a RegExp would be needed if more than one.
Mike Hale wrote:But you will have to search all the layerComps and there still may be problems if the comps have similar names.
Another approach would be if the layerComp is always in the same place in the comps panel. For example it is always the second comp. Then you could reference the comp by index.
Re-reading the original post it appears that OP wants a GUI for selecting the layer comp and possibly the replacement text... not really difficult but not something I have the time to do for free right now...
-
Mike Hale
Replacing suffix in Layer Comps
It's true that split would work. But RegExp would allow for more precision in matching if needed. I think the main problem is getting the reference. Seems to me it needs to loop the comps. get by index, or of course a UI.