Highlighted

Random brush stroke

Community Beginner ,
Jan 16, 2019

Copy link to clipboard

Copied

I download this script that randomly fill all selected paths with the selected swatches:

mySelection = app.activeDocument.selection;

myDoc = app.activeDocument;

if (mySelection instanceof Array)

{

selSwatches = myDoc.swatches.getSelected();

if(selSwatches.length != 0)

for (i=0; i<mySelection.length; i++)

{

if(mySelection.typename == "PathItem" || mySelection.typename == "CompoundPathItem")

{

selItem = mySelection;

selItem.filled = true;

swatchIndex = Math.round( Math.random() * (selSwatches.length - 1 ));

if(selItem.typename == "PathItem")

selItem.fillColor = selSwatches[swatchIndex].color;

else

selItem.pathItems[0].fillColor = selSwatches[swatchIndex].color;

}

}

}

I would like to adapt it to stroke randomly with all selected brushes

TOPICS
Scripting

Views

310

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Random brush stroke

Community Beginner ,
Jan 16, 2019

Copy link to clipboard

Copied

I download this script that randomly fill all selected paths with the selected swatches:

mySelection = app.activeDocument.selection;

myDoc = app.activeDocument;

if (mySelection instanceof Array)

{

selSwatches = myDoc.swatches.getSelected();

if(selSwatches.length != 0)

for (i=0; i<mySelection.length; i++)

{

if(mySelection.typename == "PathItem" || mySelection.typename == "CompoundPathItem")

{

selItem = mySelection;

selItem.filled = true;

swatchIndex = Math.round( Math.random() * (selSwatches.length - 1 ));

if(selItem.typename == "PathItem")

selItem.fillColor = selSwatches[swatchIndex].color;

else

selItem.pathItems[0].fillColor = selSwatches[swatchIndex].color;

}

}

}

I would like to adapt it to stroke randomly with all selected brushes

TOPICS
Scripting

Views

311

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 16, 2019 1
New Here ,
Aug 23, 2020

Copy link to clipboard

Copied

This would be amazingly useful!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 23, 2020 0
Engaged ,
Aug 24, 2020

Copy link to clipboard

Copied

There is no function to "get" selected brushes, but you can still choose which brushes to randomly apply.  In the snippet below, you choose a list of brushes based on a first and last.  (Brushes are numbered starting with 1 from the panel's upper left .)

 

firstBrushNo = 2; // <- enter number
lastBrushNo = 4; // <- enter number
theBrushes = app.activeDocument.brushes;
for (i = 0; i < app.selection.length; i++){
  brushIndex = Math.floor(Math.random()*((lastBrushNo - 1) - (firstBrushNo - 1) + 1)) + (firstBrushNo - 1);
  theBrushes[brushIndex].applyTo(app.selection[i]);
}

 

For example, you can choose to randomly apply the brushes between the second and fourth (inclusive). 

 

Untitled2000.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 24, 2020 0
Resources