-
Layer renaming script problem
I’m a beginner for scripting and I created simple script for my own purpose rename layer for active comp and for all comps in the project. That 2 codes are ok. But I’ve no idea how to combined both of them to one UI. However I combined them. But in that script active comp part only working. can anyone help me how to fix that. I think Master Dan can give me an Idea to fix this 🙂
function stingStartsWith (string, prefix) {
return string.slice(0, prefix.length) == prefix;
}app.beginUndoGroup("My Undo");
function allComps() {
for (var j=1; j<=app.project.numItems; j++){
var comp = app.project.item(j);
if (comp instanceof CompItem){
for (var i=1; i<=comp.layers.length; i++){
var myLayer = comp.layers[i];
var myLayerstartswith = stingStartsWith (myLayer.name, UI.mainTextGroup.mainText.text);
if (myLayerstartswith){
myLayer.selected = true;
myLayer.name = UI.secondaryTextGroup.secondaryText.text;
} else {
myLayer.selected = false;
}
}
}
}
}function currentComp() {
var comp = app.project.activeItem;
if (comp instanceof CompItem){
for (var i=1; i<=comp.layers.length; i++){
var myLayer = comp.layers[i];
var myLayerstartswith = stingStartsWith (myLayer.name, UI.mainTextGroup.mainText.text);
if (myLayerstartswith){
myLayer.selected = true;
myLayer.name = UI.secondaryTextGroup.secondaryText.text;
} else {
myLayer.selected = false;
}
}
} else {
alert("Please select a composition");
}
}app.endUndoGroup();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function createUserInterface (thisObj,userInterfaceString,scriptName){
var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName,
undefined,{resizeable: true});
if (pal == null) return pal;var UI=pal.add(userInterfaceString);
pal.layout.layout(true);
pal.layout.resize();
pal.onResizing = pal.onResize = function () {
this.layout.resize();
}
if ((pal != null) && (pal instanceof Window)) {
pal.show();
}
return UI;
};//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var resourceString =
"group{orientation:'column', alignment:['fill','fill'],alignChildren:['left','top']\
mainTextGroup: Group{orientation:'row',\
mainTextLabel:StaticText{text:'Find', preferredSize:[80,-1]},\
mainText: EditText{text:'enter find text here', characters:40}\
},\
secondaryTextGroup: Group{orientation:'row',\
secondaryTextLabel:StaticText{text:'Replace', preferredSize:[80,-1]},\
secondaryText: EditText{text:'enter replace text here', characters:40}\
},\
compGroup: Group{orientation:'row', alignment:['center', 'top']\
currentComp: RadioButton{text:'Current Comp', value:true},\
allComps: RadioButton{text:'All Comps'},\
},\
applyButton: Button{text:'Apply', alignment:['center', 'bottom']}\
}";var UI = createUserInterface(this,resourceString,"Layer Renamer v1.0");
if (UI.compGroup.currentComp == true){
UI.applyButton.onClick = function(){
currentComp();
}
}else if (UI.compGroup.allComps == true){
UI.applyButton.onClick = function(){
allComps();
}