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

Copy Object Name ot

Community Beginner ,
Jul 17, 2019 Jul 17, 2019

Copy link to clipboard

Copied

Hi folks,

I found a script on this forum, dating all the way back to 2012, from someone named JETalmage, which should copy an object's name to its note, to allow the use of Action > Select Object to multiselect it.

This doesn't appear to do anything in Adobe Illustrator 2019, however.

This is the original script:

//Script Start

//JET_X_SetNoteToName.jsx

var docRef=app.activeDocument;

var docObjects=docRef.pageItems;

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

var currObj=docObjects;

currObj.note=currObj.name;

}

//Script End

It runs, but nothing happens. If I change line 13 to look for 'typename' instead of just 'name', then it populates the Note field with the type of object ('PathItem', 'TextFrame'), so appears to be working as intended for that function.

currObj.note=currObj.typename;

This would suggest to me that the acceptable syntax for PageItems has changed and no longer allows direct reference to 'name'. Having never used a version of Illustrator before 2019, there's a bit too much time between then and now for me to track all of the changes to the syntax which might be responsible, and hence I can't work out what to do to resolve this.

It's worth noting that my actual issue would also be resolved by directly selecting all of the items of a given name via scripting as well, though it would be useful for such a script to allow the selection of a string each time, to give it some versatility.

For more detail about my problem, I have imported a layout from Microsoft Publisher, and the file within Illustrator is engorged with clipping masks and unnecessary blank boxes as a result. I can release all of the clipping masks and ungroup to get everything on a single layer, but I am left with hundreds of empty boxes named '<Type>' which I want to be able to select all at once and delete.

Thanks in advance for any help you can provide. I've got a fair amount of programming experience, but I've not used Javascript in some 20 years so I'm a bit lost, particularly with this non-standard one Adobe are using.

TOPICS
Scripting

Views

1.0K

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

correct answers 1 Correct answer

Community Expert , Jul 17, 2019 Jul 17, 2019

syntax hasn't change, the script works fine. If you don't get notes added it's because the items have no names. You have to explicitly name your objects in the layers panel for them to have names. What you see <type>, <rectangle>, <path> etc are just a generic labels Illustrator assigns to each type of object, that is not the name.

if you want to delete all <type> objects (text frames), go to Select->Object->All Text Objects to select them, then delete them. You can record that as an action.

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 17, 2019 Jul 17, 2019

Copy link to clipboard

Copied

syntax hasn't change, the script works fine. If you don't get notes added it's because the items have no names. You have to explicitly name your objects in the layers panel for them to have names. What you see <type>, <rectangle>, <path> etc are just a generic labels Illustrator assigns to each type of object, that is not the name.

if you want to delete all <type> objects (text frames), go to Select->Object->All Text Objects to select them, then delete them. You can record that as an action.

Votes

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 ,
Jul 18, 2019 Jul 18, 2019

Copy link to clipboard

Copied

Thanks very much for the quick reply, Carlos!

Ah, I did wonder if that might be what was going on. I do have objects with names, but those were also auto-populated when I imported the file. Would that also stop those from copying their names over to the note? Because those are also not working, which is why I thought maybe something had gone wrong with the script.

(Edit: I just tested and this is indeed the case. If I manually type a name, that gets copied over to the note field when running the script. So I think the ones that I thought were named are actually just the system describing the content of the text, rather than them having a proper name.)

Alas, it's not as simple as just deleting all text objects, because there are lots of other text objects I need to keep.

I'll have a think about an alternative approach and post here if I get stuck again. Thanks again.

Votes

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
Valorous Hero ,
Jul 19, 2019 Jul 19, 2019

Copy link to clipboard

Copied

you can do:

if (pageItem.typename == "TextFrame") {

pageItem.note = pageItem.contents;

}

This ought to help if the situation is that you want the text box text content in the notes.

A special behavior with Illustrator to watch out for is when manually naming the names: if the name is exactly the same as the text content, this gets ignored. It shouldn't be ignored in the scripting environment though, so I think you should be able to do pageItem.name = pageItem.contents;

Votes

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 ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Hi Silly-V,

When I try to run that in my script I get an error telling me the pageItem is undefined. I renamed it to currObj as per the rest of the script and this works, to an extent. It does now put the text contents into the note, but unfortunately not the ones which show as '<type>'. It seems to include those as just a single space (' '), which isn't very helpful in terms of selecting those specifically.

In any event, there might be some value in being able to copy the content of unnamed text objects to the note, so here's the full script which does so:

Copy TextFrame content to Note:

//Script Start

//JET_X_SetNoteToName.jsx, Silly-V amendment, AdamM tweak

var docRef = app.activeDocument;

var docObjects = docRef.pageItems;

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

     var currObj = docObjects;

     if (currObj.typename == "TextFrame") {

        currObj.note = currObj.contents;

     }

}

//Script End

Votes

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
Contributor ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

LATEST

Just for for optimization, you could go for something like this:

//Script Start 

   

//JET_X_SetNoteToName.jsx, Silly-V amendment, AdamM tweak 

   

var docRef = app.activeDocument; 

   

var docTextFrames = docRef.textFrames; 

 

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

        var currObj = docTextFrames

        currObj.note = currObj.contents; 

 

//Script End 

It will loop through textFrames only.

Votes

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 ,
Jul 18, 2019 Jul 18, 2019

Copy link to clipboard

Copied

Select > Object > Stray Points.

That easy. Ah well, that'll teach me to over-complicate things and to properly test all the standard tools at my disposal first.

Votes

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
LEGEND ,
Jul 18, 2019 Jul 18, 2019

Copy link to clipboard

Copied

I'm a bit lost, particularly with this non-standard one Adobe are using.

The thing is, you're dealing with artwork imported from a different program. It's not that Adobe is using, as you say, a "non-standard" Javascript implementation. It's just that different programs have different object models. Microsoft Publisher has its own constructs, as does Adobe Illustrator, as does Affinity, CorelDraw, Canvas, Inkscape or anything else. So when you import your Publisher content into Illustrator, it's not a 1:1 correspondence in terms of the constructs as created in Publisher. Everything has to be interpreted into native Illustrator constructs.

Javascript is a versatile and approachable enough language that it makes a good candidate for scripting graphics applications. But the JavaScript language itself doesn't know diddly about  the object constructs in Publisher or Illustrator, or anything else. That's where the program-specific API object model comes in; the software publisher's library of objects expressed in terms to be addressable by JavaScript code. So it is quite "standard" practice for various programs to have to provide the necessary API for the scripting language(s) it wants to support.

The primary user reference for that is the Javascript Reference Guide for Illustrator.

Ah well, that'll teach me to over-complicate things...

Don't beat yourself up, Adam. You've discovered that Illustrator has a command expressly for selecting what it calls "stray points." It has a few similar commands for selecting a few other things. But that whole set of commands is frankly rather lame compared to, for example, the far more capable Graphic Find & Replace feature in Illustrator's historic rival, Macromedia FreeHand. So there's all kinds of other things to select by name for which you can find JavaScript a suitable workaround for missing functionality.

For just one simple example, back when I was still doing Javascripts for Illustrator (which I ceased as soon as the whole rental-only license scheme was imposed), I had a script for selecting paths of any length shorter than a user-specified threshold. That saved a lot of time dealing with artwork imported from CAD exports.

JET

Votes

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