Skip to main content
Known Participant
Sep 15, 2012 7:11 PM UTC
Question

Scripts: Select an object with a note, duplicating and applying swatch

I am trying to write a Javascript that can do the following:

 

1) Select an object whose note has <Object Name> (so its layers is also selected)

2) Duplicate the layer of that object

3) Rename the new layer to <Layer Name>

4) Apply a swatch to the object on the new layer (the object is only single colour)

5) Apply a new note to the object (over-writing the original note).

 

I also want to write a separate script that can do the following:

1) Select an Object whose note has <Object Name> (so its layer is selected as well)

2) Hide all other layers

3) Save a copy of the document with a specific name

 

I can do this as an Illustrator action. However, I need several different copies of the scripts where the Object Name, Layer Name, Swatch and File Name changes.

Re-recording the action to change the names is cumbersome.

I have looked at the Illustrator scripting reference, but cannot see any commands for select objects by their notes.

I was wondering if someone could give me some pointers on how to proceed (Or possibly, if feeling very generous, could write the script for me )

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

Inspiring
Sep 15, 2012 7:41 PM UTC

This will show you how to select based on object note… My example selects muppets… This is hard coded by script will let you input/change this from a dialog box where your action wouldn't…

#target illustrator

var doc = app.activeDocument;

var allMyArt = doc.pageItems;

var toSelect = Array();

for ( var i = 0; i < allMyArt.length; i++ ) {

 

          if ( allMyArt.note == 'muppet' ) { toSelect.push( foo ) };

};

doc.selection = toSelect;

I may need screen grabs to get a better understanding of your problem ( a simplified example of layers expanded is best ) B4 and after…

Translate
big_smileAuthor
Known Participant
Sep 15, 2012 7:56 PM UTC

Thank you for your help. When I run the script, it says FOO is undefined. Here is the before and after:

(I've removed some of the layers to make the screenshots more compact, but the ones left still have the attribute names)

Translate
Inspiring
Sep 15, 2012 8:01 PM UTC

That's my error changing variables before posting… I can't edit that post now but this should fix it… Plus give you a very basic UI to enter a value…

#target illustrator

var n = prompt( 'Please enter your \'Note\' string…', 'muppet', 'Note finder' );

findNote( n );

function findNote( n ) {

          var doc = app.activeDocument;

          var allMyArt = doc.pageItems;

          var toSelect = Array();

          for ( var i = 0; i < allMyArt.length; i++ ) {

                    if ( allMyArt.note == n ) { toSelect.push( allMyArt ) };

          };

          doc.selection = toSelect;

};

Oh I didn't mean b4 n after running a duff script… What you do with actions so I can see what objects are duplicated where then coloured…

Translate