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

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

Participant ,
Sep 15, 2012 Sep 15, 2012

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 )

TOPICS
Scripting
6.4K
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
Guru ,
Sep 15, 2012 Sep 15, 2012

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
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
Participant ,
Sep 15, 2012 Sep 15, 2012

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

before.jpg

after.jpg

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

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
Guru ,
Sep 15, 2012 Sep 15, 2012

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
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
Participant ,
Sep 15, 2012 Sep 15, 2012

Hi Thanks for your help. I have sent you a private message.

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
Guru ,
Sep 15, 2012 Sep 15, 2012

I have the PM and will take a look over it tomorrom… Getting late now UK time zone…

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
Engaged ,
Oct 20, 2024 Oct 20, 2024
LATEST

the line 

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

in order to work, it must be as follows 

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

 

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
New Here ,
Sep 04, 2013 Sep 04, 2013

I really like this script. I have been playing around with the note feature and I am finding that a lot can be done by applying notes to text as well as graphics.

What I would like to figure out how to do is have a script that will select a text line with a specific note and either have a simple drop down that enters text or allows me to type in a dialog that will place the text on the line for me. Something to save me a few steps of selecting a text box, selecting the text and then changing the text.

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