Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Create new Render Path Templates via script

Explorer ,
Oct 22, 2024 Oct 22, 2024

I want to create a script that I deploy to all AE users in the studio. In this script, there shall be a button which adds custom create Render Cue Path templates to the AE settings.

 

I've tried to manilulate the txt containing the settings via JS, but AE refuses to reload the file despite calling app.preferences.reload(). It keeps the settings in memory from boot time, and overwrites all changes I made with JS on quite.

 

So I tried to use the build in app.preferences.savePrefAsString(). But the data I try to edit is weirdly formatted:

 

 

["Output File Name Template Presets Section v6"]
	"000" = "Kompositionsname"00"[compName].[fileExtension]"00

 

 

"000" is the key, "Kompositionname" is the name of the template and "[compName].[fileExtension]" is the path. So it's a string setting, with one key, but two string values, which the second is surrounded by two 00.
I can new key, with names with 
app.preferences.savePrefAsString(), but how can I add my paths.

Any JS string composition will be rendered unsuable by After Effects, as the methon introduces 22 to escape the " I add into the string. Here's a simple version of the script, I would like to use.

 

 

function padStart(number, length) {
    var str = String(number);
    while (str.length < length) {
        str = '0' + str; 
    }
    return str;
}


var presets = [
    {
        "name": 'New Render Path Preset MP4'"
        "path": "[projectFolder]//mp4//[dateYear][dateMonth][dateDay]_[dateYear][dateMonth][dateDay]_[projectName]_[compName]_[timeHour]h[timeMins].[fileExtension]"
    },
];

var prefSection = "Output File Name Template Presets Section v6";
var foundKeysCount = 0; 

try {
    var lastIndex = 0;

    while (true) {
        var key = padStart(lastIndex, 3); 
        var existingName = app.preferences.getPrefAsString(prefSection, key);

        if (!existingName) {
            break;
        }

        foundKeysCount++; 
        lastIndex++; 
    }
    
} catch (e) {
    // Empty catch block to prevent breaking execution
}

alert("Found " + foundKeysCount + " existing presets.");


for (var i = 0; i < presets.length; i++) {
    app.preferences.reload();
    var presetKey = padStart(lastIndex + i, 3);
    var presetName = presets[i].name;
    var presetPath = presets[i].path;
    var presetString = presetName + presetPath;
    app.preferences.savePrefAsString(prefSection, presetKey, presetString);    
    app.preferences.saveToDisk();
}


var addedCount = presets.length; // All presets are added in this case
alert("Successfully added " + addedCount + " new entries to the preferences.");

 

 

TOPICS
Expressions , Resources , Scripting
215
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 22, 2024 Oct 22, 2024

This is the proper presets code (I don't see any edit button?):

var presets = [
    {
        "name": "New Render Path Preset MP4",
        "path": "[projectFolder]//mp4//[dateYear][dateMonth][dateDay]_[dateYear][dateMonth][dateDay]_[projectName]_[compName]_[timeHour]h[timeMins].[fileExtension]"
    },
];
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 22, 2024 Oct 22, 2024
LATEST

I didn’t understand what you’re trying to do, but your code produces results on my end.

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