Skip to main content
Inspiring
December 12, 2021
Answered

Save an animation preset with a script and then customize the file explorer it opened

  • December 12, 2021
  • 2 replies
  • 2323 views

So for the context, I'm working on a script and and what it has to do now is to save an animation preset, the only way to do that is by using : app.executeCommand(3075); what it does is that basically presses the button to save the preset ( so it opens you the file explorer and you have to name it + save it yourself )

I have 3 small questions linked to each other:

1. Is there a way to put a "default directory" for that file explorer? ( Considering I'm not using the way to just open the file explorer, I'm using app.executeCommand(3075); and it opens the " save an animation preset " file explorer)

2. Is there a way to to customize that window? Like changing the extension, the title, etc. ) just like when we would do that : new File("Default File Name").saveDlg(["Title"],["PNG Files:*.png"]);

3. Is there a way to know what the user wrote inside of that file explorer? ( like the name he put to the file )

I know that's a lot of question, but this whole file world is not really clear for me

Thanks in advance,
Redy

This topic has been closed for replies.
Correct answer ConstantinMaier

Hey, I'd have some ideas for workarounds:

 

quote

1. Is there a way to put a "default directory" for that file explorer? ( Considering I'm not using the way to just open the file explorer, I'm using app.executeCommand(3075); and it opens the " save an animation preset " file explorer)

 

I just tested this successfully: so, the file explorer always opens up from the last folder. And that also goes for from where you applied a preset. So the idea would be to create a dummy ffx preset from where you want the default directory to be and apply the preset to your comp. Then delete it from the comp and from the directory. Now execute the command to save the preset and the file explorer should open from the directory you applied the preset from.

 

 

quote

2. Is there a way to to customize that window? Like changing the extension, the title, etc. ) just like when we would do that : new File("Default File Name").saveDlg(["Title"],["PNG Files:*.png"]);

 

Maybe you could copy a text to your clipboard and then paste it once the dialog opens. But this would be really hacky and I'm not sure whether it would work. I haven't been able to make it work yet when using AE's paste command. Maybe it'll work when forcing keyboard commands (like Ctrl+V)? I once have been able to make an enter keypress work on one these dialogs by simulating an enter keypress with AutoIt on Windows and via AppleScript on Mac right before I executed the dialog. Maybe the same would apply for pasting? Not sure. Also, this would, of course, be only to give it a default name. Other than that, I don't think there is a way to do any other modifications.

 

 

quote

3. Is there a way to know what the user wrote inside of that file explorer? ( like the name he put to the file )

 

Hm, not sure. The only thing I could think of right now would be to scan all possible folders first and then after the file has been saved to look for a new ffx file. But that might be quite insane since there would be probably too many folders on your computer to scan. Another interesting note though: once you save an animation preset, it will be listed with its name under "Recent Animation Presets". The menu command ID for the most recent preset is "2460". However, I don't know how to get the name from the command ID (usually it's just the other way around ;)). If you could somehow get the name, you would know what the user typed in.

2 replies

ConstantinMaier
ConstantinMaierCorrect answer
Inspiring
December 12, 2021

Hey, I'd have some ideas for workarounds:

 

quote

1. Is there a way to put a "default directory" for that file explorer? ( Considering I'm not using the way to just open the file explorer, I'm using app.executeCommand(3075); and it opens the " save an animation preset " file explorer)

 

I just tested this successfully: so, the file explorer always opens up from the last folder. And that also goes for from where you applied a preset. So the idea would be to create a dummy ffx preset from where you want the default directory to be and apply the preset to your comp. Then delete it from the comp and from the directory. Now execute the command to save the preset and the file explorer should open from the directory you applied the preset from.

 

 

quote

2. Is there a way to to customize that window? Like changing the extension, the title, etc. ) just like when we would do that : new File("Default File Name").saveDlg(["Title"],["PNG Files:*.png"]);

 

Maybe you could copy a text to your clipboard and then paste it once the dialog opens. But this would be really hacky and I'm not sure whether it would work. I haven't been able to make it work yet when using AE's paste command. Maybe it'll work when forcing keyboard commands (like Ctrl+V)? I once have been able to make an enter keypress work on one these dialogs by simulating an enter keypress with AutoIt on Windows and via AppleScript on Mac right before I executed the dialog. Maybe the same would apply for pasting? Not sure. Also, this would, of course, be only to give it a default name. Other than that, I don't think there is a way to do any other modifications.

 

 

quote

3. Is there a way to know what the user wrote inside of that file explorer? ( like the name he put to the file )

 

Hm, not sure. The only thing I could think of right now would be to scan all possible folders first and then after the file has been saved to look for a new ffx file. But that might be quite insane since there would be probably too many folders on your computer to scan. Another interesting note though: once you save an animation preset, it will be listed with its name under "Recent Animation Presets". The menu command ID for the most recent preset is "2460". However, I don't know how to get the name from the command ID (usually it's just the other way around ;)). If you could somehow get the name, you would know what the user typed in.

RedyCodeAuthor
Inspiring
December 12, 2021

For some reason, the alert(3) doesn't show up, as if it doesn't go into the for loop... Do you know why?

        // EFFECTS
        // =======
        presetPath = File(""+File($.fileName).path+"/Styles/!Styles ( IGNORE ME ).data"); // It's basically an empty preset, I changed extension from .ffx to .data
        thisComp.selectedLayers[0].applyPreset(presetPath); // Doing this so the "save an animation preset" file explorer opens at the right location

        alert(1);
        
        thisComp.selectedLayers[0].property("Effects").property("Styles").remove(); // Delete the useless .data "preset"

        alert(2);

        // Select all effects so the script can create a preset
        for (i = 1; i <= thisComp.selectedLayers[0].property("Effects").numProperties; i++) {
            thisComp.selectedLayers[0].property("Effects").property(i).selected = true;
}
        alert(3);
        // Save preset + Tell instructions
        alert("*DISCALIMER*\n\nThe script will open a window so you can save your style, make sure to save it to the location the window has opened to")
        app.executeCommand(3075);
ConstantinMaier
Inspiring
December 13, 2021

That's so smart!!!

Thanks, thanks, thanks and thanks!

I have small a issue tho:

I can't do the action "simKeypress("Enter");" when the file explorer to save the preset is opened, it just does it after I closed it

any fixes?


If you write:

app.executeCommand(3075);
simKeypress("Enter");
endKeypress();

 

...the keypress is simulated after the dialog, meaning after the dialog has been closed. However, you can also write:

simKeypress("Enter");
app.executeCommand(3075);
endKeypress();

 

That way the VBS file will be executed before the app.executeCommand(3075), however since the keypress will be executed independent of AE and it takes a little bit until the file is actually executed, it should happen at the same time as the file browser opens. I just tested this code successfully and the dialog will be clicked way automatically. However, in rare instances I found that the keypress doesn't work (less than 1% of cases). But since this is quite hacky, it's not guaranteed to always work and I'm not sure whether it works for everyone on every machine to honest.

Mylenium
Legend
December 12, 2021

Long and short: No, no and no. When you use menu commands, the default AE behavior takes over. You can only control any of that by writing your own file dialog, but even that won't help you much. unlike e.g. in Photoshop's file dialogs, most options cannot be accessed by scripts in AE. It's just a black box.

 

Mylenium