Sg2.9
Control Calligraphic Thickness
Recent RSS
Control Calligraphic Thickness
From:  Squis
Date:  3. February 2007, 22:58

Something I have been missing in AI: The possibility to retroactively control the thickness of calligraphic brush strokes. NOT with just a stylus, but tweaking the width of specific portions of a stylus-drawn stroke AFTER it has been drawn. Either with point-for-point control, or something more generic: "Start thin, go wide in the middle, end thin again".

That's what I've been dreaming of.

Re: Control Calligraphic Thickness
From:  Hiroyuki Sato
Date:  4. February 2007, 02:03

Does the following script match your need?
But there will be more appropriate tweaks to "Start thin, go wide in the middle, end thin again".

// A sample script to change pressure values applied on the foreground path
var pathes = activeDocument.getMatchingItems(Path,{selected: true});
if (pathes.length > 0){
  var p = pathes[0];          // get the foreground path in the selection
  var td = p.getTabletData(); // gettabletdata
 var str; // # (the lines marked '#' were added on 11.02.07)
  if(!td){ // #
    str = "no tabletData";  // #
  } else { // #
    // show the information as a text object
    var str = 'length:' + td.length + "r"; // it's an array.
    for(var i=0; i<td.length; i++){ // Each item has properties.
      str += i + ': offset:' + td[i].offset.toFixed(4) // They are 'offset'
        + '  value:' + td[i].value.toFixed(4) + "r";  // and 'value'.
    }
  } // #
  var ptxt = new PointText(p.bounds.center); // create an text object
  ptxt.range.characterStyle.fontSize = 8;
  ptxt.content = str;

  if(td){ // #
    // now, change the values
    // # it isn't work nicely if there isn't enough number of elements in tabletData
    for(var j=0; j<td.length; j++){
      with(td[j]){
        if(offset < 0.2) value *= offset/0.2;
        else if(offset > 0.8) value *= (1-offset)/0.2;
      }
    }
    
    p.setTabletData(td); // apply it

    // apply same data to the background pathes in the selection #
    if(pathes.length > 1){ // #
      for(var j=1;j<pathes.length;j++){ pathes[j].setTabletData(td); } // #
    } // #
  } // #
}
Re: Control Calligraphic Thickness
From:  Squis
Date:  4. February 2007, 10:52

Praise Scriptographer!!

That looks a lot like what I've been looking for! I shall have to try that out soon! Thanks!

Is there such a script available at the moment?

Re: Control Calligraphic Thickness
From:  Hiroyuki Sato
Date:  5. February 2007, 13:31

I tried writing it, by modifying above script.
This script changes the pressure values applied on the selected brushes at both ends.
Usage: Select brush strokes, select this script in Sg's palette, then press Run button on the palette.
Note that minimum thickness of the brush depends on the setting of it.

# last modified: 2007-02-11 : add a quick-fix to ignore strokes that aren't created with a stylus pen.

Re: Control Calligraphic Thickness
From:  Jürg Lehni
Date:  5. February 2007, 16:20

Thank you, Hiroyuki! I'm impressed you found out about how to use the tablet data feature.
Just a little note: Instead of using the getter / setter functions directly, you can also use the data like this (through the so called bean properties).

var td = path.tabletData;
...
path.tabletData = td;

Also, please note that there is a maximum of supported data. I cannot remember if it was 256, 512 or 1024 pairs, but it was something like that.

Re: Control Calligraphic Thickness
From:  Hiroyuki Sato
Date:  10. February 2007, 16:19

That limit in the number of elements is what I was concerned about.
Because I wrote the script without understanding enough about Ai's brush.
In above script, I'm adding 2 elements to the tabletData.
If there's that limit, it may cause an error or an unexpected result.
So I tried drawing very long strokes with a brush.
But they had only 50 or so tabletData-elements at a maximum.
It seems that there is no need to worry ...?

By the way, to tell the truth, I thought to create that kind of brush tool as a plugin recently.
I read Ai-SDK's document to find it's too difficult to me for now, but I understood the brief of the tabletData.
And also I found that Ai-SDK's document is even very helpful to understand Sg's functions.

Re: Control Calligraphic Thickness
From:  alex
Date:  10. February 2007, 21:20

Hiroyuki- excellent stuff! I've been trying to work out a similar tool for a while, and looks like it will cut the work needed in half! I can't seem to get it to excecute properly though. Each time I run either script above, it returns null on the getTabletData, or seems to crash on the setTabletData function. Does the path need to be created with a tablet to have the tabletData array populated?

Re: Control Calligraphic Thickness
From:  Hiroyuki Sato
Date:  11. February 2007, 02:09

It seems that only a path drawn with Brush Tool and a calligraphy-brush has a tabletData. It need not necessarily a stylus pen.

The script I uploaded first (on 04.02.07) was just a simple sample and had no error handling. It causes a crush if a path has no tabletData.
It was too careless, indeed.
I added the lines marked '#' to avoid errors to the first script.

Also, I added an additional process at the end of it.
It seems that it's possible to apply a tabletData to a path that has no tabletData.

The second script does nothing if a path has no data.
But both of these do not work nicely if a path is not drawn with a stylus pen.
I will fix the second one about this issue.

Re: Control Calligraphic Thickness
From:  Hiroyuki Sato
Date:  11. February 2007, 04:53

It seems that the data added in the second script wasn't applied to the stroke.
I made a quick-fix on 'taper.js' to avoid an unexpected result with strokes that wasn't drawn with stylus pen.
But it needs other kind of tweak to work nicely in any case.

Re: Control Calligraphic Thickness
From:  alex
Date:  20. February 2007, 22:38

I've been experimenting with this for a few days, and have gotten mixed results with brush paths created without a tablet. I'd like to do some more research, but lack the data... Can someone post or email a CS2 .ai file containing a tablet-drawn brush path? One saved as a plain file (without pdf compatability and compression) would be preferred. Any help would be appreciated!

Re: Control Calligraphic Thickness
From:  alex
Date:  1. March 2007, 16:03

I don't mean to beg, but I really would like to see how the tabletData array is structured. If a full file is out of the question, then just the path's data along with it's tabletData would be just fine!

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Crop Marks 14.02.12
by Zed