ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change with Placeholder and use proxy

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mateo Mazzini
Change with Placeholder and use proxy
on Apr 10, 2018 at 2:03:28 pm

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 &lt;= 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


Return to posts index

Dan Ebberts
Re: Change with Placeholder and use proxy
on Apr 10, 2018 at 4:13:42 pm

For the first error, my guess is that you might be messing up the item order while you're looping through them.

Dan



Return to posts index

Mateo Mazzini
Re: Change with Placeholder and use proxy
on Apr 14, 2018 at 1:09:51 pm
Last Edited By Mateo Mazzini on Apr 14, 2018 at 1:15:05 pm

I reduced the script so it's easier to read and tried to remake the FOR sentences to be cleaner... I save the sources in an array first and then convert everything to a placeholder. finally I set the proxy for the placeholder based on the sources array.
But the problem still there and is the same error... If I apply the script on a new file with some files imported, it works the first time, but if you UNDO and try to apply it again... doesn't work.

Could it be that After effects doesn't update correctly the sources files after undoing?

also... the base code to set proxy always work... the problem is just when I try to add the feature of replacing with placeholder.




app.beginUndoGroup("setproxytoself");

var allSelectedSources= new Array();

for (i=1 ; i <= app.project.numItems ; i++){
var pItem=app.project.item(i);
if (pItem.selected==true){
var pSource=pItem.mainSource.file;
allSelectedSources[i]=pSource;
};
};

for (a=1 ; a <= app.project.numItems ; a++){
var pItem=app.project.item(a);
if (pItem.selected==true){
pItem.replaceWithPlaceholder('placeHolder',1920,1080,30,3)
pItem.setProxy(allSelectedSources[a])
};
};



Return to posts index


Dan Ebberts
Re: Change with Placeholder and use proxy
on Apr 14, 2018 at 5:45:03 pm

I think you still have the same problem. I think I'd set it up this way:


var selectedItems = app.project.selected; // get array of selected items
for (var i = 0; i <selectedItems.length; i++){ // process the array
// do stuff
}



Dan



Return to posts index

Mateo Mazzini
Re: Change with Placeholder and use proxy
on Apr 15, 2018 at 2:58:24 pm
Last Edited By Mateo Mazzini on Apr 19, 2018 at 6:00:34 pm

Hi Dan, thank you for your help! I tried the .selection method and it's more optimized indeed. it does the iteration better without any miss elements.
The problem with the UNDO feature remains though. this script works perfect the first time. but if you undo and apply it again, it won't make the setProxy part on any video element you have on your project file and it will give you the error "unable to call setProxy because of parameter 1. Value is undefined".

This is the code as I have it now with the .selection property.

app.beginUndoGroup("placeHolderAndProxyToSelf");

var pItem = app.project.selection;

for (i=0 ;i<pItem.length ; i++){
var pSource=pItem[i].mainSource.file;
alert(pSource);
pItem[i].replaceWithPlaceholder('placeHolder',1920,1080,30,3)
pItem[i].setProxy(pSource)
};


Matz


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]