-
Change with Placeholder and use proxy
I am trying to make a script which would change all selected footage in the project window to a placeholder with the original source as a proxy.
I have two errors which I can’t wrap my mind around.1- I have a WHILE reading the project window for selected objects and replacing them with placeholders, but when using the same WHILE to setProxy for the current object, sometimes works, sometimes it doesn’t (especially if you undo and try again).
2- In the version I’m sharing here, the code replaces the footage with a placeHolder with a generic name, because if I try to store the name with app.project.item(i).name I can’t apply it later to the placeHolder if the original name used a convention like “footage_A_01[000-150].jpg”. does anyone knows how to standardize a string to be fully compatible with javascript?
this is a script UI panel so store under scriptUIpanels folder if you want to try it!
thanks!
{
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;// While there remain elements to shuffle...
while (0 !== currentIndex) {// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}return array;
}function myScript(thisObj) {
function myScript_buildUI(thisObj) {
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Placeholder Manager", [0, 0, 30, 60]);res = "group{orientation:'column', alignment:['fill', 'top'], alignChildren:['fill', 'top'],\
myGroup: Group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\
topText: StaticText{text:'Overrides:',alignment:['left','fill']}\
myCheckWidth: Checkbox{active:false,text:'Width',alignment:['left','center']}\
myWidth: EditText{text:'1920',enabled:false},\
myCheckHeight: Checkbox{active:false,text:'Height',alignment:['left','center']}\
myHeight: EditText{text:'1080',enabled:false},\
myCheckFps: Checkbox{active:false,text:'FPS',alignment:['left','center']}\
myFps: EditText{text:'30',enabled:false},\
myCheckDuration: Checkbox{active:false,text:'Duration (in frames)',alignment:['left','center']}\
myDuration: EditText{text:'90',enabled:false},\
myCheckRelink: Checkbox{value:true,active:false,text:'Relink to source',alignment:['left','center']}\
myButton: Button{text:'Make Placeholder'},\
},\
}"// Adds resource string to panel
myPanel.grp = myPanel.add(res);// Assign function to UI elements
// Enabled, disabled functions
//WIDTH
myPanel.grp.myGroup.myCheckWidth.onClick = function(){
if(myPanel.grp.myGroup.myCheckWidth.value==true){
myPanel.grp.myGroup.myWidth.enabled=true;}else{
myPanel.grp.myGroup.myWidth.enabled=false;}
};//HEIGHT
myPanel.grp.myGroup.myCheckHeight.onClick = function(){
if(myPanel.grp.myGroup.myCheckHeight.value==true){
myPanel.grp.myGroup.myHeight.enabled=true;}else{
myPanel.grp.myGroup.myHeight.enabled=false;}
};//FPS
myPanel.grp.myGroup.myCheckFps.onClick = function(){
if(myPanel.grp.myGroup.myCheckFps.value==true){
myPanel.grp.myGroup.myFps.enabled=true;}else{
myPanel.grp.myGroup.myFps.enabled=false;}
};//DURATION
myPanel.grp.myGroup.myCheckDuration.onClick = function(){
if(myPanel.grp.myGroup.myCheckDuration.value==true){
myPanel.grp.myGroup.myDuration.enabled=true;}else{
myPanel.grp.myGroup.myDuration.enabled=false;}
};// THE SCRIPT
myPanel.grp.myGroup.myButton.onClick = function(){
app.beginUndoGroup("PlaceHolder");
var placeWidth=parseInt(myPanel.grp.myGroup.myWidth.text);
var placeHeight=parseInt(myPanel.grp.myGroup.myHeight.text);
var placeFps=parseFloat(myPanel.grp.myGroup.myFps.text);
var placeDuration=parseInt(myPanel.grp.myGroup.myDuration.text)/placeFps;
var i = 1;
while (i <= app.project.numItems){
if (app.project.item(i).selected==true){
var pName='placeholder';
var pWidth=app.project.item(i).width;
var pHeight=app.project.item(i).height;
var pFps=app.project.item(i).frameRate;
var pDuration=app.project.item(i).duration;
var pSource=app.project.item(i).mainSource.file;
if(myPanel.grp.myGroup.myCheckWidth.value==true){
pWidth=placeWidth;
};
if(myPanel.grp.myGroup.myCheckHeight.value==true){
pHeight=placeHeight;
};
if(myPanel.grp.myGroup.myCheckFps.value==true){
pFps=placeFps;
};
if(myPanel.grp.myGroup.myCheckDuration.value==true){
pDuration=placeDuration;
};if(pFps==0){var pFps=1};
app.project.item(i).replaceWithPlaceholder(pName,pWidth,pHeight,pFps,pDuration)// THE RELINK FUNCTION
if(myPanel.grp.myGroup.myCheckRelink.value==true){app.project.item(i).setProxy(pSource)};
};
i++;
};
app.endUndoGroup("PlaceHolder")
};// Setup panel sizing and make panel resizable
myPanel.layout.layout(true);
myPanel.grp.minimumSize = myPanel.grp.size;
myPanel.layout.resize();
myPanel.onResizing = myPanel.onResize = function () {this.layout.resize();}return myPanel;
};// Build script panel
var myScriptPal = myScript_buildUI(thisObj);if ((myScriptPal != null) && (myScriptPal instanceof Window)) {
myScriptPal.center();
myScriptPal.show();
}
}// Execute script
myScript(this);
}
Matz