Skip to main content
Inspiring
October 24, 2022
Answered

Running the script a second time, ae crashes

  • October 24, 2022
  • 1 reply
  • 385 views

I tried writing a script to quickly replace placeholders and it worked, but the second time I ran it, AE crashed

    var myComp = app.project.activeItem;
    var ml = myComp.selectedLayers[0];
    if (ml.source.frameRate === 0) {
        var ml_Source_FrameRate = 1;
    }else{
        var ml_Source_FrameRate = ml.source.frameRate;
    };
 
    function searchLayer(string) {
        var itemNum = app.project.numItems;
        for (searchLayerIndex = 1; searchLayerIndex <= itemNum; searchLayerIndex++) {
            if (app.project.item(searchLayerIndex).name === string) {
                if (app.project.item(searchLayerIndex).file.fsName ===  ml.source.file.fsName) {
                    return searchLayerIndex;
                }
            };
        }
        return false;
    }

    searchLayer(ml.source.name);
    var ml_source_name = ml.source.name;
    app.project.item(searchLayerIndex).replaceWithPlaceholder("__placeholder__", ml.source.width, ml.source.height, ml_Source_FrameRate, ml.source.duration);
    ml.source.name = ml_source_name;
}

How can I modify it so that it can run the second time without ae crashing?
This topic has been closed for replies.
Correct answer damomoyu

Sorry I found the cause of the error in my unpublished code, now it's fixed...

1 reply

Mylenium
Legend
October 24, 2022

You may need to add a check for the layer type. After the first replacement procedure AE may simply try to replace a placeholder with another. Also the last curly brace doesn't seem to belong anywhere, so maybe it's throwing up on that because it expects a function.

 

Mylenium

damomoyuAuthor
Inspiring
October 24, 2022

Sorry, I'm missing some operations.
After I ran it the first time it was successful, I tried ctrl+z to restore it, and when I ran it again, ae crashed
I have tried not to use ctrl+z, after the material is replaced with a placeholder, re-replace the placeholder with a new material, and then run on this material, ae crashes
Please ignore the last "}", this is my wrong operation

damomoyuAuthorCorrect answer
Inspiring
October 24, 2022

Sorry I found the cause of the error in my unpublished code, now it's fixed...