Copy link to clipboard
Copied
I must be missing something really simple here.
The "patterns" collection has an add() function, which adds an empty pattern. This shows up as a chequered black and white swatch. But how do you add anything to this empty pattern (analogous to dragging an item into the swatches panel to create a pattern)?
Otherwise, what would be the point of the add() function here? Similarly, what would be the point of the PatternColor() constructor, since a new patternColor will need a "pattern" object?
Thanks in advance.
I dont believe you can create patterns via scripts but i did come across this post and a solution by Carlos that maybe of use.
https://community.adobe.com/t5/illustrator/how-to-create-pattern-in-ai-script/m-p/9601219#M80221
By combining scripting with recorded actions you can achieve the required functionality, you just need to create an action that creates a pattern and then call that action via doScript(). After the action is ran, you can grab the last pattern in document.patterns[document.patt
...Sorry to reply to myself, but this solution may help future users with the same issue. It uses executeMenuCommand and a temporary VBScript to interact with the dialogue. It is basically an imitation of this idea by @Qwertyfly___ .
/*
* Create Pattern (Windows) by Femke Blanco
* Beta 21/05/2022
* Instructions: Select item to make pattern from
*/
var temp;
{
interactWithDialog();
app.executeMenuCommand("Adobe Make Pattern");
}
function interactWithDialog() {
var contents =
...
Copy link to clipboard
Copied
I dont believe you can create patterns via scripts but i did come across this post and a solution by Carlos that maybe of use.
https://community.adobe.com/t5/illustrator/how-to-create-pattern-in-ai-script/m-p/9601219#M80221
By combining scripting with recorded actions you can achieve the required functionality, you just need to create an action that creates a pattern and then call that action via doScript(). After the action is ran, you can grab the last pattern in document.patterns[document.patterns.length - 1] (not tested but if i remember correctly, it will be the last item in there)
Copy link to clipboard
Copied
Thanks for the tip. It looks like that's the way things are heading.
I'm holding onto one last thread of hope of doing it without an action. I've found an executeMenuCommand which creates a pattern from a selected item,
app.executeMenuCommand("Adobe Make Pattern");but this brings up the "patterns options" dialogue box.
The question is: is it possible to emmulate the escape key with a script? I'm hoping that the thread I found this on is old enough that someone might have found a workaround.
Thanks again.
Copy link to clipboard
Copied
Sorry to reply to myself, but this solution may help future users with the same issue. It uses executeMenuCommand and a temporary VBScript to interact with the dialogue. It is basically an imitation of this idea by @Qwertyfly___ .
/*
* Create Pattern (Windows) by Femke Blanco
* Beta 21/05/2022
* Instructions: Select item to make pattern from
*/
var temp;
{
interactWithDialog();
app.executeMenuCommand("Adobe Make Pattern");
}
function interactWithDialog() {
var contents =
'Set WshShell = WScript.CreateObject("WScript.Shell")\n' +
'WshShell.SendKeys "{ENTER}"\n' +
'WshShell.SendKeys "{ESCAPE}"';
temp = new File("~/Desktop/temp.vbs");
temp.open("w");
temp.write(contents);
temp.close();
temp.execute();
}
temp.remove();
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more