Highlighted

Script crashing AE and I can't find out why

Community Beginner ,
Jun 07, 2020

Copy link to clipboard

Copied

Hey there, first time posting here.

Tried my best to find the solution for this on this forum and everywhere else but no success.

So, I'm trying to apply some effects to a layer and then duplicate it via a button in my script. The applying part works if not followed by the duplicate() part and vice-versa, but when I try to assemble the steps, it crashes AE.

Here's the code:

function example() {
    app.beginUndoGroup('Example');
    var thisComp = app.project.activeItem;
    applyFx(thisComp.selectedLayers[0]);
    thisComp.selectedLayers[0].duplicate();
    app.endUndoGroup();

    function applyFx(target) {
        var fx = target.property("ADBE Effect Parade");
        var timeDiff = fx.addProperty("ADBE Difference");
        timeDiff.property(2).expression = "thisLayer.source.frameDuration";
        timeDiff.property(4).setValue(1);
        var colorControl = fx.addProperty("ADBE Color Control");
        colorControl.property(1).expression = "t = thisLayer;\nt.sampleImage([0,0],[t.width,t.height],true);";
    }
}

 The only thing I can think of is the script tries to duplicate the layer while the effects are still being added.

Thanks for the help!

Correct answer by bcandeias | Community Beginner

Alright, so if someone's having the same issue, just found the solution by the one and only Dan Ebberts over on creativecow.

Apparently, you can't add sampleImage expression to a layer by script and leave it there, but you can add it, harness the value and remove it later.

Cheers!

TOPICS
Crash, Error or problem, Scripting

Views

257

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Script crashing AE and I can't find out why

Community Beginner ,
Jun 07, 2020

Copy link to clipboard

Copied

Hey there, first time posting here.

Tried my best to find the solution for this on this forum and everywhere else but no success.

So, I'm trying to apply some effects to a layer and then duplicate it via a button in my script. The applying part works if not followed by the duplicate() part and vice-versa, but when I try to assemble the steps, it crashes AE.

Here's the code:

function example() {
    app.beginUndoGroup('Example');
    var thisComp = app.project.activeItem;
    applyFx(thisComp.selectedLayers[0]);
    thisComp.selectedLayers[0].duplicate();
    app.endUndoGroup();

    function applyFx(target) {
        var fx = target.property("ADBE Effect Parade");
        var timeDiff = fx.addProperty("ADBE Difference");
        timeDiff.property(2).expression = "thisLayer.source.frameDuration";
        timeDiff.property(4).setValue(1);
        var colorControl = fx.addProperty("ADBE Color Control");
        colorControl.property(1).expression = "t = thisLayer;\nt.sampleImage([0,0],[t.width,t.height],true);";
    }
}

 The only thing I can think of is the script tries to duplicate the layer while the effects are still being added.

Thanks for the help!

Correct answer by bcandeias | Community Beginner

Alright, so if someone's having the same issue, just found the solution by the one and only Dan Ebberts over on creativecow.

Apparently, you can't add sampleImage expression to a layer by script and leave it there, but you can add it, harness the value and remove it later.

Cheers!

TOPICS
Crash, Error or problem, Scripting

Views

258

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 07, 2020 0
Most Valuable Participant ,
Jun 08, 2020

Copy link to clipboard

Copied

I tend to agree with your assessment. You may need to implement an extra check/ break and structure your script more.

 

Mylenium

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2020 1
Community Beginner ,
Jun 08, 2020

Copy link to clipboard

Copied

Thanks for the answer!

Any suggestions on what would be best practice for this situation? I'm not really a programmer, just an enthusiast. Tried using async functions but I guess it's not compatible.

 

Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2020 0
Community Beginner ,
Jun 11, 2020

Copy link to clipboard

Copied

Alright, so if someone's having the same issue, just found the solution by the one and only Dan Ebberts over on creativecow.

Apparently, you can't add sampleImage expression to a layer by script and leave it there, but you can add it, harness the value and remove it later.

Cheers!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2020 0