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

how to create pattern in ai script

Community Beginner ,
Dec 31, 2017 Dec 31, 2017

in aiscript,i create a placeitem(picture),and i want to use it to fill the pathitem.like this:

var r=new patterncolor();

patterncolor.pattern=the pictue i want

pathitem.fillcolor=r;

so,how to convert placeitem to pattern.or how to filled the pathitem by the picture i want?

TOPICS
Scripting
3.4K
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 1 Correct answer

Community Expert , Jan 03, 2018 Jan 03, 2018

Hi trymoremore, unfortunately we can't create pattern swatches from PlacedItems using new PatternColor().

As a workaround you can record an action to Make a Pattern, then you can play such Action using doScript() function.

to record an action to turn placedItems into Pattern Swatches

1. select your placed item

2. embed it

3. open Actions Panel, start recording

4. Insert Menu Item...(in Actions Panel Flyout Menu)

5. Object->Pattern->Make

6. Exit Pattern Editing Mode (in Layers Panel Flyout Menu)

7. Stop

...
Translate
Adobe
Community Expert ,
Dec 31, 2017 Dec 31, 2017

Hi trymoremore​,

you are here in the illustrator main forum - that's the wrong forum for your question.

How good is your scripting knowledgebase?

Perhaps a Moderator can move this thread to the right forum: Illustrator Scripting

I think you doesn't mean the following kind of pattern. Please explain in detail with screenshot (and perhaps with example ai-file) what you really want.

For the beginning a sample code in [JS] (read and alert the name of swatches with pattern):

var doc = activeDocument;

var theSwatches = doc.swatches;

for (var i=0; i <= theSwatches.length-1; i++) {

    swatchType = theSwatches.color.typename;

    swatchName = theSwatches.name;

    // alert name of pattern swatch

    if (swatchType == "PatternColor") {alert(swatchName)};

}

Have fun and a Happy New Year 2018

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
Community Beginner ,
Dec 31, 2017 Dec 31, 2017

thank you for help! i will set the question in the right fourm.happy new year! 

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
Community Expert ,
Dec 31, 2017 Dec 31, 2017

[moved from Illustrator​ to Illustrator Scripting​]

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
Community Beginner ,
Jan 01, 2018 Jan 01, 2018

thank you for your patience and please forgive me for not responding promptly.

i want to filled the pathitem by the picture i want just like this :1.png

2.png

my idea is create a placeitem ,and convert the placeitem to pattern.then,create a patterncolor and Specify its “pattern” as the pattern the placeitem convertd. at last,use the patterncolor fill the pathitem.

So,what i don't know is how to convert placeitem  to pattern.

this is my code:

var patternColors = new PatternColor();

patternColors.pattern=pattern the placeitem convert;

pathitem.fillColor=patternColors;

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
Community Expert ,
Jan 03, 2018 Jan 03, 2018

Hi trymoremore, unfortunately we can't create pattern swatches from PlacedItems using new PatternColor().

As a workaround you can record an action to Make a Pattern, then you can play such Action using doScript() function.

to record an action to turn placedItems into Pattern Swatches

1. select your placed item

2. embed it

3. open Actions Panel, start recording

4. Insert Menu Item...(in Actions Panel Flyout Menu)

5. Object->Pattern->Make

6. Exit Pattern Editing Mode (in Layers Panel Flyout Menu)

7. Stop Recording

patternMakerAction.PNG

then in your script, with your embedded placed item selected use

app.doScript("yourActionName", "yourActionSetName")

in my example, it would be

app.doScript("recreatePatternMaker", "test")

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
Community Beginner ,
Jan 03, 2018 Jan 03, 2018

thanks for your help! my version of ai is cs6,whether this version can record an action?and whether the script you said is VBscript but not javascript? i am fool in it,please forgive me.

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
Community Expert ,
Jan 03, 2018 Jan 03, 2018

I did not post a script, I just described the method.

yes, you can record the actions and use doScript() with CS6

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 ,
Jan 03, 2018 Jan 03, 2018

bonjour,

Je propose une alternative au motif.

clipped.PNG

var docRef = activeDocument;

var obj = docRef.rasterItems[0]; //docRef.placedItems[0];

var newGroup = docRef.groupItems.add();

var dupobj = obj.duplicate(newGroup,ElementPlacement.PLACEATEND);

var cercle = newGroup.pathItems.ellipse(-300,200,80,80,false,true);

var c1, c2, dx, dy;

c1 = centreObj(cercle);

c2 = centreObj(dupobj); 

dx = c1[0]-c2[0]; 

dy = c1[1]-c2[1]; 

dupobj.translate(dx,dy); 

newGroup.clipped = true;

// ----

function centreObj(objet) {

  var rect = objet.geometricBounds;

  return [(rect[2]+rect[0])/2,(rect[1]+rect[3])/2];

}

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
Community Beginner ,
Feb 13, 2020 Feb 13, 2020
LATEST

Just found this script that could cover steps 1 & 2:

#target Illustrator

if ( app.documents.length > 0 ) {
    while ( app.activeDocument.placedItems.length > 0 ) {
        placedArt = app.activeDocument.placedItems[0];
        placedArt.embed();
    }
}

 Source: https://graphicdesign.stackexchange.com/a/71642

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