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

How to apply a brush and keep stroke weights

Community Beginner ,
Mar 11, 2020 Mar 11, 2020

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

 

TOPICS
Scripting
2.5K
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
Adobe
LEGEND ,
Mar 11, 2020 Mar 11, 2020

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;
        }
    }

 

 

 

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
LEGEND ,
Mar 12, 2020 Mar 12, 2020

Ok, thanks to some help from a friend, here's a better script with a dropdown menu of current brush names:

image.png

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;
    }
}


 

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 ,
Mar 12, 2020 Mar 12, 2020

Perfect!

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 ,
Mar 12, 2020 Mar 12, 2020

Great job, Ray. Getting better.

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
LEGEND ,
Mar 13, 2020 Mar 13, 2020

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. 🙂

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 ,
Apr 14, 2020 Apr 14, 2020

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.

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 ,
Mar 19, 2020 Mar 19, 2020

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

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
LEGEND ,
Mar 19, 2020 Mar 19, 2020

@vagh_studio

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.

 

 

 

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 ,
Mar 12, 2020 Mar 12, 2020

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

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 ,
Mar 12, 2020 Mar 12, 2020

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

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 ,
Mar 12, 2020 Mar 12, 2020

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.

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
LEGEND ,
Mar 13, 2020 Mar 13, 2020

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-...

image.png

 

 

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 ,
Apr 14, 2020 Apr 14, 2020

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

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
LEGEND ,
Apr 14, 2020 Apr 14, 2020

Certainly possible. I'll see if I can find some time today to play with the idea.

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 ,
Apr 14, 2020 Apr 14, 2020

Really appreciate 🙂

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
LEGEND ,
Apr 14, 2020 Apr 14, 2020

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.

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 ,
Apr 15, 2020 Apr 15, 2020
LATEST

Dear mcgraihead!

It works so well. Thank you very much

 

vagh_studio

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