Script for automatically changing path directions

Community Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

I need a script for Illustrator that does the following:

  1. First path follows clockwise direction
  2. Second path inside the 1. Path follows a countclockwise direction
  3. Third path inside the 2. path follows clockwise direction .... and this cycle repeats...

To Illustrate what I mean see the picture:

Unbenannt-1.jpg

and this follows, depending on the amount of paths inside each other.

Does anyone knows how to solve this?

Thank you in advance!

TOPICS
Feature request, Scripting, Third party plugins, Tools

Views

182

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
community guidelines
Adobe Community Professional ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Is doing it by hand an option?

 

- select all your circles

- grab the Shape Builder Tool

- puch holes with it

- apply PathFinder Unite

- ungroup

- release Compound Paths

 

Carlos

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
community guidelines
Community Beginner ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Hey Carlos,

 

doing by hand is not an option because I need to edit hundres of vector data and this would take me a lot of time to do everything manually.

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
community guidelines
Adobe Community Professional ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Which version of Illustrator are you using?

 

Also, in cases like this one it is often recommendable to provide at least one meaningful sample Illustrator file (.ai) to demonstrate a representative situation. This way, it is much easier to brood about possible automated ways.

 

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
community guidelines
Community Beginner ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

I am using the lastest Illustrator version.

 

I need an automated way of doing this since I am not editing one file specifically but figuring out how to edit hundreds of files.

Paths need to be organised this way I've described because it will be used for laser marking and the software for that reads the data this way for correct lasermarking.

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
community guidelines
Community Beginner ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

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
community guidelines
Enthusiast ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

var d1 = prompt("diameter (in points) of outer circle");
var n = prompt("number of circles");
var d = app.activeDocument.artboards[0].artboardRect;
var paths = app.activeDocument.pathItems;
var direction = false;
for (var i = 0; i < n; i++) {
    var d2 = (d1/n) * (n-i) ;
    direction = !direction;
    var circle1 = paths.ellipse(d[3]/2+d2/2, d[2]/2-d2/2, d2, d2, direction);
    circle1.stroked = true;
    circle1.filled = false;
}

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
community guidelines
Adobe Community Professional ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Femkeblanco, do you think that your approach is a reliable way without checking a sample file?

 

I'm not sure.

 

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
community guidelines
Enthusiast ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

I agree.  It's a shot in the dark. 

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
community guidelines
Community Beginner ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Here is an example file 😄

 

https://we.tl/t-DQwWveLHb3

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
community guidelines
Adobe Community Professional ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Clint Eastwood had some good shots in the dark some years ago.

 

But he was always careful and clear-sighted.

 

Nonetheless, your snippet is very good.

 

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
community guidelines
Community Beginner ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Hi Kurt, Like I said in the previous comments,

 

I will be editing hundreds of different vector files, and I need to be able to follow this "logic" I've described above.

Outer Path must follow clockwise. First inner paths must follow counterwise, and so on and on.

See an example 😄

 

path-example.jpg

 

 

 

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
community guidelines
Community Beginner ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

https://we.tl/t-DQwWveLHb3v Here is the example file of what I described above

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
community guidelines
Engaged ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

A shorthand to doing this is to rely on the native menu item via Object > Path > Reverse Path Direction:

(function() {
  var actionString =
    "/version 3 /name [ 11 7265766572736550617468 ] /isOpen 1 /actionCount 1 /action-1 { /name [ 11 7265766572736550617468 ] /keyIndex 0 /colorIndex 0 /isOpen 1 /eventCount 1 /event-1 { /useRulersIn1stQuadrant 0 /internalName (ai_plugin_reversePathDirection) /localizedName [ 22 	52657665727365205061746820446972656374696f6e ] /isOpen 0 /isOn 1 /hasDialog 0 /parameterCount 0 } }";
  function runActionFromString(actionName, actionSet, contents) {
    var tmp = File(Folder.desktop + "/reversePath.aia");
    tmp.open("w");
    tmp.write(contents);
    tmp.close();
    app.loadAction(tmp);
    app.doScript(actionName, actionSet, false);
    app.unloadAction(actionSet, "");
  }
  runActionFromString("reversePath", "reversePath", actionString);
})();

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
community guidelines
Adobe Community Professional ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

or 

app.executeMenuCommand("Reverse Path Direction");

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
community guidelines
Engaged ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

I looked for that! But I didn't see it on this list so I assumed we had to do it via action. Where do you go to look for the canonical list of menu commands?

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
community guidelines
Enthusiast ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

This is the list I use, but it's not on this either:

https://ten-artai.com/illustrator-ccver-22-menu-commands-list/ 

 

Also, I don't think there any other ways to reverse the direction of an already-created path with scripting, are there?  

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
community guidelines
Adobe Community Professional ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

LATEST

I didn't see it in the list either, so I just experimented a little, I got lucky with the menu name.

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
community guidelines
Adobe Community Professional ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Hi all,

just to play:

app.activeDocument.pathItems[0].polarity = (app.activeDocument.pathItems[0].polarity == PolarityValues.NEGATIVE)  ? PolarityValues.POSITIVE : PolarityValues.NEGATIVE;

 

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
community guidelines
Adobe Community Professional ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

But honestly?
This is a job for the laser software (but not Illustrator)

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
community guidelines