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

How to create a pattern with a script

Guide ,
Mar 26, 2021 Mar 26, 2021

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. 

TOPICS
Scripting
1.2K
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

correct answers 2 Correct answers

Participant , Mar 26, 2021 Mar 26, 2021

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

...
Translate
Guide , May 21, 2022 May 21, 2022

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 = 
    
...
Translate
Adobe
Participant ,
Mar 26, 2021 Mar 26, 2021

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)

 

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
Guide ,
Mar 27, 2021 Mar 27, 2021

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.

 

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
Guide ,
May 21, 2022 May 21, 2022
LATEST

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();

 

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