Copy link to clipboard
Copied
Hallo,
I want to know if there is a chance to draws paths with different thicknesses and then assign a brush from the libraries that maintains the thickness of each individual stroke. thank you
vagh_studio
Copy link to clipboard
Copied
See if this works for you:
Edit 2: I've added a prompt so you can type the "Brush Name" within the script. I want to learn how to have the user choose from a list of current brush names, but am not quite there yet.
assignBrush ();
function assignBrush (){
var aDoc = app.activeDocument;
var brush = prompt ("Type brush name");
var myBrush = aDoc.brushes[brush];
var sel = app.selection;
var i;
for ( i = 0; i < sel.length; i++){
var myPath = aDoc.selection[i];
var pathWidth = myPath.strokeWidth;
myBrush.applyTo(myPath);
myPath.strokeWidth = pathWidth;
}
}
Copy link to clipboard
Copied
Ok, thanks to some help from a friend, here's a better script with a dropdown menu of current brush names:
brushDialog();
function brushDialog(){
var aDoc = app.activeDocument;
var b = [];//Brush Name Array
var i;
for ( i = 0; i < aDoc.brushes.length; i++){
b.push (aDoc.brushes[i].name);
}
//~ Code for Import https://scriptui.joonas.me
var brushName = new Window("dialog");
brushName.text = "Choose a Brush";
brushName.preferredSize.width = 350;
brushName.orientation = "row";
brushName.alignChildren = ["center","top"];
brushName.spacing = 10;
brushName.margins = 12;
var dropdown1_array = b;
var dropdown1 = brushName.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array});
dropdown1.selection = 0;
dropdown1.preferredSize.width = 250;
var button1 = brushName.add("button", undefined, undefined, {name: "button1"});
button1.text = "Ok";
brushName.show();
var myBrush = aDoc.brushes[dropdown1.selection];
var sel = app.selection;
var i;
for ( i = 0; i < sel.length; i++){
var myPath = aDoc.selection[i];
var pathWidth = myPath.strokeWidth;
myBrush.applyTo(myPath);
myPath.strokeWidth = pathWidth;
}
}
Copy link to clipboard
Copied
Perfect!
Copy link to clipboard
Copied
Great job, Ray. Getting better.
Copy link to clipboard
Copied
Thanks Larry and Ton. I've been on a quest the last 2 years learning Javascript. It's nice to be able to answer a few questions now instead of always asking them. 🙂
Copy link to clipboard
Copied
no shame at all in asking lots of questions. Each time someone asks a question, they get to learn something, and the rest of us might get to learn something too. Very frequently it happens that the way people word their question makes me think about an issue in a different way than i had been. more often than not, this change in perspective is what leads me to the answer.
so, thank YOU for asking lots of questions.
Copy link to clipboard
Copied
Hallo Craig, so, I had to replace the brush name I want apply anytime I see brushName into the script above, right?
Forgive me the elementary question. Thanx
vagh_studio
Copy link to clipboard
Copied
If you downloaded the latest version here brushDialog.jsx
it should give you a pulldown menu of all the brushes in your current document. It is not perfect. If there are no brushes it will be blank.
Copy link to clipboard
Copied
Just in case vagh_studio was not expecting a script answer and is new to using a script, see: https://helpx.adobe.com/illustrator/using/automation-scripts.html
Copy link to clipboard
Copied
Yes Frederiks, you hit the mark. I have never used the script but I'll try to follow the directions. I use Illustrator experimentally and creatively. you see something inherent @vagh_studio IG page
Thank you for answering
PS. I'm pretty sure once I apply a brush and keep stroke weights using simply AI C6
Copy link to clipboard
Copied
Scripts are a good way to automate or add functions in Illustrator.
What the help file does not tell is how to save a script as shown above.
Copy the script text.
Open a text editor (TextEdit or Notepad)
Paste the text in a text only document (no formatting).
Save the document with a .jsx extension.
From Illustrator you can just browse to the script using File > Scripts > Other Scripts when you don't need it frequently.
Copy link to clipboard
Copied
Here's a JSX file ready to use.
brushdialog.jsx
Install location can vary. For older Mac AI versions it is:
/Applications/Adobe Illustrator CC [version]/Presets.localized/en_US/Scripts
This link may help for PC and later AI CC versions:
https://community.adobe.com/t5/illustrator/installing-scripts-in-latest-illustrator-cc-release-v-22-...
Copy link to clipboard
Copied
dear rCraighead thanks to your script!
I managed to speed up some operations that are useful for my graphic work.
A next step would be to be able to increase a set of tracks with different thickness with an increase in percentage. I mean, increase the thickness but not the length. Do you think it's possible?
Thank you so much for all
vagh_studio
Copy link to clipboard
Copied
Certainly possible. I'll see if I can find some time today to play with the idea.
Copy link to clipboard
Copied
Really appreciate 🙂
Copy link to clipboard
Copied
This should work. Make sure to enter the percentage with decimal point.
//by Ray Craighead
//Resize selected path stroke width(s) by percentage.
function scalePathWidth(){
var aDoc = app.activeDocument;
var sel = app.selection;
if (sel.length < 1){
alert ('Make a selection of paths and try again');
return;
}
else
{
var myInput;
userPrompt();
var myPercent;
function userPrompt(){
myInput = prompt('Scale Percentage (0.1 = 100%)', .100);
myPercent = Number(myInput);
}
for (var i = 0; i < sel.length; i++) {
var myWidth = sel[i].strokeWidth;
sel[i].strokeWidth = myWidth * myPercent;
}
}
}
scalePathWidth();
And here's a .jsx file you can download and install:
https://www.dropbox.com/s/yjg7jrj7wkak5p8/scalePathWidth.jsx?dl=0
Edit: I noticed I left an unused variable so I updated the script.
Copy link to clipboard
Copied
Dear mcgraihead!
It works so well. Thank you very much
vagh_studio
Find more inspiration, events, and resources on the new Adobe Community
Explore Now