Hey -
Thanks again.
Now as mentionned earlier I did a test at the end of the process/script with:
"app.executeMenuCommand("simplify menu item");"
But it pops up a window requesting an user input, which I don't want.
I want the process to be fully automated, I mean fully transparent for the user (w/o any action requested except the one of launching the script 😉 )
I guess that we can't set a default value here and click the OK button without any interaction of the user?
Thx…
- Dimitri
So, there is no easy answer for Simplify (that I know of). The Simplify command was changed in recent history so
I am not sure what I have included below will work for you since I think you are on a different version of Ai than me but you should be able to recreate the steps on your end.
Option 1:
Create a Simplify action, ensure it is loaded on any computer running your script, execute the action in your code using `app.doScript("Action Name", "Action Set Name");`. But, if you plan to distribute your script this has one huge downside... How do you get the action set setup on every users computer?
Option 2:
Use a dynamic action. This is a way of creating a temporary action within your code, loading it into the users Ai, executing it, and then cleaning up after yourself. The setup can get pretty crazy but I think your needs are simple so here are the steps.
Creating a base action (with your required settings) to work from:
- Go to the Actions panel and create a new action set (remember the set name)
- Create a new action inside of that set (remember the action name)
- Record a 1-step action of running Object > Path > Simplify with the settings you want to use
- Stop the action recording
- Click the new action set you created (not the actual action)
- Under the 3 line menu at top of Actions palette, click "Save Actions..."
Now you'll need to open that saved action file (.aia extension) in a text editor so we can use the text inside to create a temporary action inside of the script. Bascially, each line in the exported .aia file needs to be converted to a string and concatenated together.
Action text to string conversion and concatenation (in a clean text file)
- Paste in the text from the .aia file
- Add a double-quote (") to the START and END of every line
- Add a + to the end all lines ecvept the last (after the double-quote)
- Add `var actionCode =` to the first line (before the double-quote)
Now that you have the action code into a single javascript variable, you can place that in your script code. I like to wrap everything into a single function so I can easily call it.
function myCustomDynamicAction() {
var actionCode =
"/version 3" +
"/name [ 5" +
" 5365742032" +
"]" +
"/isOpen 1" +
"/actionCount 1" +
"/action-1 {" +
" /name [ 8" +
" 53696d706c696679" +
" ]" +
" /keyIndex 0" +
" /colorIndex 0" +
" /isOpen 1" +
" /eventCount 1" +
" /event-1 {" +
" /useRulersIn1stQuadrant 0" +
" /internalName (ai_plugin_simplify)" +
" /localizedName [ 8" +
" 53696d706c696679" +
" ]" +
" /isOpen 0" +
" /isOn 1" +
" /hasDialog 1" +
" /showDialog 0" +
" /parameterCount 4" +
" /parameter-1 {" +
" /key 1919182693" +
" /showInPalette 4294967295" +
" /type (unit real)" +
" /value 12.0" +
" /unit 592474723" +
" }" +
" /parameter-2 {" +
" /key 1634561652" +
" /showInPalette 4294967295" +
" /type (unit real)" +
" /value 21.0" +
" /unit 591490663" +
" }" +
" /parameter-3 {" +
" /key 1936553064" +
" /showInPalette 4294967295" +
" /type (boolean)" +
" /value 0" +
" }" +
" /parameter-4 {" +
" /key 1936552044" +
" /showInPalette 4294967295" +
" /type (boolean)" +
" /value 0" +
" }" +
" }" +
"}";
var tmp = File(Folder.desktop + "/Simplify.aia");
tmp.open("w");
tmp.write(actionCode);
tmp.close();
app.loadAction(tmp);
app.doScript("Simplify", "Set 2");
app.unloadAction("Set 2", "");
tmp.remove();
}
// do some stuff in your script
...
// run your custom dynamic action
myCustomDynamicAction()
// do some more stuff in your script
...
What the function does
- Creates a temporary file on the users desktop
- Writes the action code from the initial .aia file into the temporary file
- Loads the temporary action set into Ai (named Set 2)
- Executes your custom action (named Simplify)
- Removes the temporary action set from Ai
- Removes the temporary .aia file from the users desktop
FYI
You could make the custom action "customizeable" where you can set the Simplify settings from within your code, you just need to determine which parameters in the action code text need to be adjusted.
function myCustomDynamicAction(customSetting) {
var actionCode =
"/version 3" +
...
" /parameter-1 {" +
" /key 1919182693" +
" /showInPalette 4294967295" +
" /type (unit real)" +
" /value " + customSetting +
" /unit 592474723" +
" }" +
...
}
// do some stuff in your script
...
// run your custom dynamic action
myCustomDynamicAction(17)
// do some more stuff in your script
...
More Info
I didn't come up with this so there are folks far more knowledgeable than me that have written about this.
- Creating a dynamic action to use with app.doScript() method by @Silly-V
- Solution by @Ten A
- LinkedIn Article by Vasily Hall
Hopefully this gets you pointed in the right direction... Let me know if you have any issues. Cheers!
Sign up
Already have an account? Login
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inSign in to Adobe Community
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.
