Showing posts with label Illustrator. Show all posts
Showing posts with label Illustrator. Show all posts

Feb 14, 2014

distributeOnThePath.jsx

distributes the selected objects in the equal distance on the foreground path in the selection.

USAGE: select the objects and run this script.

test env: Adobe Illustrator CC (Win/Mac)

download: bg_distributeOnThePath.zip -> http://shspage.com/ex/files.html

rotateTowardPoint.jsx



rotates the objects in the selection toward the center of the foreground object.

USAGE: select the objects and run this script.

test env: Adobe Illustrator CC (Win/Mac)

download: bg_rotateTowardPoint.zip -> http://shspage.com/ex/files.html

Apr 30, 2012

Join the separated lines of 3D/CAD data


Recently I received a mail from the owner of the site ADi Kiteboarding.
He said that he wanted to edit the data exported from 3D application, but the lines are separated and couldn't be connected each other properly even he used my script "Join Reasonably.js".

I'd heard sometimes that some people were also using "Join..." script to join the lines the data of 3D/CAD application.  So I tried to write one to be able to join the lines like this kind of data.  This time I post this one with the agreement of Adi.

Received data was like the above image(left).  It was constructed from the paths like the above image(right).   Some part of the paths were overlapped.  So complicated.

It seemed that connecting from point to point needed a complex algorithm.
So I decided to use the segment ( the line between 2 anchors ) as a unit.
The script breaks all the paths into segments and removes overlapped segments.  Then it connects the segments if its end points are closer than the threshold (0.1mm).  If there's no more near point, it creates another path from the rest of paths.

As a preparation, like the red line of the above image(left), connect the points that too far away, and delete the branched lines.   Then select all the paths you want to connect, and run the script.  The overlapped paths and the isolated points are deleted by the script.

Edit the settings in the script if needed.

As a specification for now, like the above image(right), the script cannot work as you expect in the case that only lines are overlapped and points are not.

download: join_reasonably_2.zip -> http://shspage.com/ex/files.html


Tested with Adobe Illustrator CS5 15.0.2 / Windows XP SP3
This is a beta software. Please use it carefully, at your own risk.



Jun 12, 2011

connect_centers_nearest_modified 2


Here's a little tutorial about the script that I uploaded yesterday.
The source objects are the brush objects in Fig.1.  The red one is the foreground (last drawn).  And the distance between the farthest removed objects is about 88pt.
Select all the brush objects, then run the script.
A prompt dialog appears.  Input 80 and hit OK.
Fig.2 is the result.  Paths are separated because the distance between the nearest object is longer than the specified value (80pt).

Jun 11, 2011

connect_centers_nearest_modified

I thought about how to create the objects to connect these centers by the script that I wrote previous time. And remembered a software Voronoi Stippler that I used a few years ago. (For some reason, it seems that it is unavailable for download now.)

I made the objects from an image with this tool, then applied the connect_centers_nearest.js script to them ... and got an error due to the upper limit of the number of points that setEntirePath function allows.

So I rewrote a part of the script as follows. Then I ran it again.
//path.setEntirePath(points);
for(i=0; i<points.length; i++){
with(path.pathPoints.add()){
anchor = points[i];
rightDirection = anchor;
leftDirection = anchor;
}
}
It seemed to be interesting. But it looked also like an ugly entangled string. So I implemented the idea of the maximum distance of the line to the script. If the distance between the points is longer than the limit, the script finishes the path and begins a new path from the next point.
This seems to be good? I posted this script at the end of this article.

In the archive, the script with .js extention is for windows. And .jsx is for Mac. When you run this script, you are asked the maximum distance in point. (Actually, it is the maximum squared distance. This is not appropriate. But I leave it as it is for now.)
Talking about the code, I put 0 instead of the coordinate [x, y], at the point that separates the paths.

download: aics_script_connect_centers_nearest_modified2.zip -> http://shspage.com/ex/files.html

2011.06.12 -- fixes length_limit to be squared 

May 28, 2011

connect centers in various order


These scripts create a path that traces the center of the selected objects. The path starts from the center of the foreground object. And the order of the connection vary from script to script. If the number of points is greater than two, the path is closed.
I thought the "farthest" is unexpectedly interesting.

download: b_aics_script_connect_centers.zip -> http://shspage.com/ex/files.html

Tested with Adobe Illustrator CS5 15.0.1 / Windows 7 Pro 64bit
This is a beta software. Please use it carefully, at your own risk.

And
I bought macbook pro recently. Though I don't have Illustrator works on it yet. I must be familiar with Xcode first.

May 30, 2010

I installed AI CS5

The most important change in this version I noticed is a change in the coordinate system.
I must apply a little fix to several of my scripts to let them work with CS5.

Take a look at "Changes in CS5" section in "Illustrator CS5 Scripting Guide" PDF document for the details.

Jan 4, 2010

Cutting Marks

This script may help to draw cutting marks.
(As an answer to the request.)

download: b_aics_script_cutting_marks.zip -> http://shspage.com/ex/files.html

Jul 5, 2009

image: Buildings

This is an image with rot3d.js effect.
I wrote a supplementary small script to randomize the heights of the buildings.

Jun 30, 2009

Sg: rot3d Updated - 06.30

Though there's few response over there, I like tweaking this script (rot3d.js) and uploaded modified version to www.scriptographer.com again.

In this version, it has "fix-z-order" checkbox in the palette. If this option is checked, this script changes the z-order of the objects according to the z-axis value of the center of the each object. Please note that it doesn't always work properly, and this process may destruct the groups.

Another script "rot3d_m.js" that I uploaded yesterday doesn't have this feature.

Jun 28, 2009

Sg: rot3d Updated

I've uploaded another edition of rot3d.js to www.scriptographer.com (as an attachment file to the comment). There's no new feature but some modification of the inside process.

Jun 24, 2009

image: Random Tile




This is the initial state of the above image -- paved hexagonal shapes. As you can imagine, simply randomizing every point creates just messy image. The overlapping points must keep its condition even after randomizing. This script uses an associative array to do this.

download: b_aics_script_random_tile_example.zip -> http://shspage.com/ex/files.html

Jun 21, 2009

image: Spiral Sphere


This script creates 2 groups of pathes -- front and back side -- and a circle as an outline.

The sphere's center is the origin of the artboard -- (x, y, z) = (0, 0, 0). And the viewing point is (x, y, z) = (0, 0, infinity). This means the virtual eye is not looking down the sphere. Rather the sphere is leaning toward the eye.

This assumption makes it so simple to check the current point is at the front or back side. It is just to check if the z-axis value is greater than zero or not.

download: b_aics_script_spiral_sphere.zip -> http://shspage.com/ex/files.html

Jun 19, 2009

Fixing Sequential Numbers

[edit: 2018-10-03]
a script for Adobe Illustrator CSx-CCx

For the selected text objects, this script changes each content so that they become a sequential numerical values at even intervals from the backmost value to the foremost value.

For the number of decimal places and the number of zero-filled digits, the largest one of the foremost value and the backmost value is adopted.
(Fractions are rounded off as necessary.)

ex. (the left end is the backmost and the right end is the foremost)
  • 1 1 1 1 5     -> 1 2 3 4 5
  • 1.0 x x x 5   -> 1.0  2.0  3.0  4.0  5.0
  • 1 1 1 1 5.00  -> 1.00  2.00  3.00  4.00  5.00
  • 1.0 1 1 1 6   -> 1.0  2.3  3.5  4.8  6.0
  • 1 1 1 1 6     -> 1 2 4 5 6
  • 01 1 1 1 5    -> 01 02 03 04 05
  • 00 1 1 1 1 10 -> 00 02 04 06 08 10
 download:
 b_aics_script_fixing_sequential_numbers_20181003.zip -> http://shspage.com/ex/files.html

Jun 13, 2009

Selected Status of Anchor Points

With Illustrator's scripting function, you can examine the selected state of any anchor point (PathPoint), and let a script affect only for anchors which are in particular state.

The available values are:
  • ANCHORPOINT
  • LEFTDIRECTION
  • LEFTRIGHTPOINT
  • NOSELECTION
  • RIGHTDIRECTION
With the following script, you can check the state that each anchor point is in.
// shows selected state of each anchor of the selected path
var pi = activeDocument.selection[0];
var p = pi.pathPoints;

for(var i = 0; i < p.length; i++){
alert( p[i].selected );
}
The following another simple script selects every other anchor of the selected pathes.
(Grouped pathes and compound pathes are ignored.)
// selects every other anchor of the selected pathes.
var sel = activeDocument.selection;

var p, i;
for(var j = 0; j < sel.length; j++){
sel[j].selected = false;
p = sel[j].pathPoints;

for(var i = 0; i < p.length; i++){
if( i % 2 == 1 )
p[i].selected = PathPointSelection.ANCHORPOINT;
}
}
After running this script, you can apply the effect of tools only to the selected anchors.

Jun 9, 2009

image: Circles on Sphere

This is an image generated by Illustrator script.

Basically, the method is simple. It is to draw an ellipse, then rotate it around the center of the large circle. This is not an accurate expression of 3D object. But I think it can not be a problem for the purpose of this case.

Light colored shapes mean that they are on the back side of the sphere.
At first, it seemed that they're sligntly unnatural in size, so I added perspective factor to the size of the ellipses.

download: b_aics_script_circles_on_sphere.zip -> http://shspage.com/ex/files.html

Jun 7, 2009

Drawing a Dot With 2 Anchors

I often draw a dot with 2 anchors.
To draw this, drawing a horizontal line and set the width of it to zero, then set the stroke cap type to the Round Cap.


This method enables to seve the number of anchors as compared with drawing a circle with 4 anchors.
Additionally, if you set Resize tool's option to keep the stroke width, you can adjust the density of dots without scaling each of them.

To use the dot, I usually drag it into Brush palette, and register as a scatter brush.
Then I drag on the artboard.


... Looks dirty. Let's clean it by removing the overlapped dots with a script.


Now looks OK.

Before using the following script, you must expand the brush and then ungroup it so that every item is appeared as <Path> in the Layers palette. (You may have to ungroup twice after expand it.)
Then remove useless path (the track of the brush).

If I write a script for general purpose, I'll automate this ungroup process, and insert the error handling to avoid baffling abending.
But this time, I wrote this for one-time use and for my own use.
I often write small scripts like this to automate the boring part of daily work.

// removes overlapped dots
var sel = activeDocument.selection;
var j;
var vb = sel[0].visibleBounds;
var w = vb[2] - vb[0]; // right - left
w *= 1.25; // adds margin
w *= w; // for comparison of squared distance

for(var i = sel.length - 1; i > 0; i--){
for(j = i - 1; j >= 0; j--){
if( dist2(sel[i].pathPoints[0].anchor,
sel[j].pathPoints[0].anchor) <= w ){
sel[i].remove();
break;
}
}
}
// -------
function dist2(p, q){
return Math.pow(p[1] - q[1], 2)
+ Math.pow(p[0] - q[0], 2);
}

Jun 5, 2009

Round Corners Issue

When drawing a circle with 4 points by bezier curve, the ratio of the handle length to the radius is about 0.5522847 (4 * (sqrt(2) - 1) / 3).

I thought Illustrator's "Round corners" filter (and effect) uses this ratio for the specified "radius". But I was wrong.

I measured length of the handles with a script (at end).
Maybe it uses more simple rule -- multiplying 0.55 by the radius.
Though it may not become a problem most of the time.

Anyway, it uses fixed length of handle for any corner. The corners are rounded, but they are not the arcs of specified radius most of the time.
Is it an useless low-quality tool? At least, it isn't always bad.
Applying it to the slanted rectangle like below, the effect may be as expected.
What if it strictly uses arcs in this case?
Though it is sure that it would be nice if we had that tool.

My script "Round Any Corner" (placed in my alternate site) basically uses same algorithm as above (but the ratio is 0.5522847). Because I think this method creates a neat shape that is suited for design, rather than using arcs. And to be honest, rounding the intersection point of curves by arc is difficult to script for me. Awfully troublesome at least.

It doesn't always creates arcs, and (unfortunately) isn't intended for that purpose.

// measures length of the handles
const FONT_SIZE = 9;
const FONT_NAME = "TimesNewRomanPSMT";
const DIGIT = 4;

var pi = app.activeDocument.selection[0];
var p = pi.pathPoints;
var d;

for( var i = 0; i < p.length; i++ ){
d = dist(p[i].anchor, p[i].rightDirection);
if(d > 0)
drawText( d.toFixed( DIGIT ), p[i].rightDirection);

d = dist(p[i].anchor, p[i].leftDirection);
if(d > 0)
drawText( d.toFixed( DIGIT ), p[i].leftDirection);
}
// -------
function drawText(txt, pos){
with(activeDocument.activeLayer.textFrames.add()){
contents = txt;
with(textRange){
with(characterAttributes){
size = FONT_SIZE;
textFont = textFonts.getByName( FONT_NAME );
}
with(paragraphAttributes){
justification = Justification.CENTER;
}
}
position = [pos[0] - width / 2, pos[1] + height / 2];
}
}
// -------
function dist(p, q){
return Math.sqrt(Math.pow(p[1] - q[1], 2)
+ Math.pow(p[0] - q[0], 2));
}

Jun 1, 2009

Ultra Fast Way to Draw Primitive Solids

... with Adobe Illustrator.


Cylinder
  1. Select the bottom anchor, and press Ctrl-X.
  2. Press Ctrl-F, and drag it downward with Shift key pressed.
  3. Select the right side anchors and press Ctrl-J. Do the same for the left side.
  4. Press Ctrl-F again.

Box
  1. Draw a rectangle.
  2. Drag the right side segment. Then select whole shape and press Ctrl-C.
    Then press Ctrl-F twice.
  3. Drag the left side segment.
  4. Drag the lower side segment.
  5. Select marked anchors, then drag one anchor to be snapped.
  6. Colorize as you prefer.

Cone
  1. Draw an oval.
  2. Drag with Alt key pressed to duplicate. Snap the lower anchor to the center.
  3. Drag the upper box of the bounding box with Shift key pressed, so that the shape is enlarged with keeping the aspect ratio.
  4. Draw a path with Pen tool to connect the intersection points and the upper anchor.
    -- These 2 lines are exactly tangential to the oval. (To be accurate, these are almost tangential because the oval is an approximated one by the bezier curve.)
  5. Unite with pathfinder if it needs.

May 31, 2009

Working With Symbols

The available scripting operations for symbol item are almost despairingly limited in AI CS3. As follows.

symbol properties -- name, parent, typename
symbol methods -- duplicate, remove

You can not even get coordinates of it directly.

One solution is to put a symbol into a group manually, and then you can manipulate the symbol through the group.

Suppose there's a grouped symbol on the artboard, like this.


Then you can get this image by running the following script.


// ----------------------------------------------
// places groups along a circle
const RADIUS = 120;
const DIV = 12;

with(app.activeDocument){
var gr = activeLayer.groupItems[0];
var radian = Math.PI * 2 / DIV;

for(var i = 0; i < DIV; i++){
with(gr.duplicate()){
translate( RADIUS * Math.cos(i * radian),
RADIUS * Math.sin(i * radian) );
}
}
}
// ----------------------------------------------