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

Select objects by name

Explorer ,
Jan 20, 2021 Jan 20, 2021

Copy link to clipboard

Copied

I once again throw myself at teh feet fo teh scriptors and beg for one more script. I am hoping to be able to select objects by partial name, like "Votoms" or "Expanse" so that I can apply a style to them. The object names tend to be more complicated than just the one word, with a 8 digit number and more refrence text. Is this possible? I've dug through and tried everything list here and elsewhere and cannot find a script that works.
Help me oh-be script-kenonbi, you are my last hope.

TOPICS
Scripting

Views

534

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

Enthusiast , Jan 20, 2021 Jan 20, 2021

 

You can use very basic RegExp to match character patterns inside any string no matter their location.

var ignoreCase = false; // Should it match both "hello" and "Hello"
var textToFind = prompt("Write the partial name to find")

// Create new RegExp and clear selection
var RX = new RegExp(textToFind, ignoreCase ? "i" : "")
app.selection = null;

// Iterate through pageItems
for (var i = 0; i < app.activeDocument.pageItems.length; i++) {
    // If the RegExp test on name is true, then select it
 
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Jan 20, 2021 Jan 20, 2021

Copy link to clipboard

Copied

 

You can use very basic RegExp to match character patterns inside any string no matter their location.

var ignoreCase = false; // Should it match both "hello" and "Hello"
var textToFind = prompt("Write the partial name to find")

// Create new RegExp and clear selection
var RX = new RegExp(textToFind, ignoreCase ? "i" : "")
app.selection = null;

// Iterate through pageItems
for (var i = 0; i < app.activeDocument.pageItems.length; i++) {
    // If the RegExp test on name is true, then select it
    if (RX.test(app.activeDocument.pageItems[i].name))
        app.activeDocument.pageItems[i].selected = true;
}

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
Explorer ,
Jan 20, 2021 Jan 20, 2021

Copy link to clipboard

Copied

Beautiful! Thank you so very much!

 

 

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
Guide ,
Jan 20, 2021 Jan 20, 2021

Copy link to clipboard

Copied

For simpler cases, you can use one of many string functions, e.g.

  • slice(from, to_not_including)
  • substring(from, to_not_including)
  • substr(from, length)
var name1 = "VotomsXXXXXXXX";
if (name1.slice(0, 6) == "Votoms") {
    alert(true);
}

 

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
Enthusiast ,
Jan 20, 2021 Jan 20, 2021

Copy link to clipboard

Copied

Should note that explicit string matching via sub and slice is only simpler depending on use case; if these partial matches are a guaranteed prefix and case sensitive; otherwise you'd be better off using indexOf:

 

alert(string[i].slice(0, 6) == "Votoms")
"VotomsXXXXXXXX",   // true
"XXVotomsXXXXXXXX", // false
"votomsXXXXXXXX"    // false

alert(string[i].indexOf("Votoms") >= 0)
"VotomsXXXXXXXX",   // true
"XXVotomsXXXXXXXX", // true
"votomsXXXXXXXX"    // false

alert(
        new RegExp("votoms", "i").test(string[i])
)
"VotomsXXXXXXXX",   // true
"XXVotomsXXXXXXXX", // true
"votomsXXXXXXXX"    // true

alert(
        string[i].toLowerCase().indexOf("Votoms".toLowerCase()) >= 0
)
"VotomsXXXXXXXX",   // true
"XXVotomsXXXXXXXX", // true
"votomsXXXXXXXX"    // true

 

 

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
Engaged ,
Dec 07, 2021 Dec 07, 2021

Copy link to clipboard

Copied

Hello,
I have also written a javascript that searches for objects when you enter a name or part of a name.
"$.liga" searches for all objects that end with ".liga",
"A$" searches for all objects beginning with "A" or "a".
It also searches the group and even in editable texts.
Link for more info: https://www.behance.net/gallery/132742865/Javascript-for-Illustrator-Find-objects-by-name 
Link directly for download: Javascript »FindByName.jsx«
Link to German website: http://www.computergrafik-know-how.de/javascript-objekte-nach-namen-im-illustrator-suchen/ 

Have fun with it, Jens

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 Expert ,
Dec 07, 2021 Dec 07, 2021

Copy link to clipboard

Copied

Hallo Jens aka Parts4Arts aka draupnir,

vielleicht solltest du die Beschreibung deines Scriptes noch etwas ergänzen. Dein Script eignet sich wohl am ehesten für Dokumente mit mehreren Textrahmen in denen sich eher wenig Text befindet. Für Dokumente mit wenigen langen – oder gar einem einzigem Textrahmen scheint es mir weniger geeignet, das es final lediglich den/die gefundenen Textrahmen markiert.

 

Drei kleine Dinge, die mir beim Antesten aufgefallen sind:

1) Warum gehst du über die zeitraubendere Methode, zuerst alles auszuwählen und dann nach Textrahmen zu prüfen? Warum nicht gleich über die TextFrames-Collection? Dadurch würden deine Schleifen weniger Objekte durchlaufen (bessere Performance) und du zusätzlich ist das Durchschleifen durch eine Collection noch einmal deutlich performanter als das Durchlaufen einer Selection.

 

2) Dann habe ich dein Font-Design-Band1-Flyer.pdf in Illustrator geöffnet (sollte man eigentlich nicht tun, aber dadurch erhalte ich zum Testen viele kleine zerpflückte Textrahmen) und nach dem Wort "Meine" gesucht. Es wird nichts gefunden. Da ich selbst ab und zu scripte und auch deinen Code gesehen habe, weiß ich auch, warum. Denn mit "Meine$" wird es auf jeden Fall gefunden. Doch er findet auch nichts mit "$eine" und auch nichts mit "eine$".

 

Aber ich könnte mir vorstellen, dass es deswegen die Erwartungshaltung eines unbedarften Users eventuell nicht erfüllen wird. Packe ein Beispiel-Illustrator-Dokument mit einigen Textrahmen und jeweils einem Wort pro Textrahmen mit in deine Zip. Oder erweitere deine Webseite um zwei Vorher/Nachher Screenshots. Dann sieht der Interessierte, mit welchem Dokumentenaufbau dein Script am Besten funktioniert. Und dann wird die Erwartungshaltung auch nicht enttäuscht.

 

3) Eventuell liest du dich für künftige Weiterentwicklungen deines Scriptes in die Methode exec() ein. Diese liefert dir auf "einfache" Art Anzahl, Inhalt und Positionen der Fundstellen.

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
Engaged ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

LATEST

Hello Pixxxelschupser,
the Javascript ALSO searches in text frames. However, that is not the primary goal. For that, you would indeed have to choose a different path. I have an AI document with over 1000 glyphs and wanted to know if I have already created the pathIem/symbol "(Attention:).liga". Using Javascript (new version 1.6) I can now search for different possibilities:
"$Att$" searches for all objects that contain "att" or "Att".
When using the wildcards (regex), the special characters ( ) ` * [ ] ? { } + are correctly taken into account. So I can search for "(Att$" and get all objects that begin with "(att" or ("Att".

Direct link for version 1.6: Download des Javascripts »FindByName.jsx«

 

Hallo Pixxxelschupser,

das Javascript sucht AUCH in Textrahmen. Das ist jedoch nicht das vordringliche Ziel. Dafür müsste man in der Tat einen anderen Weg wählen. Ich habe ein AI-Dokument mit über 1000 Glyphen und wollte wissen, ob ich schon das pathIem/Symbol "(Achtung:).liga" erstellt habe. Per Javascript (neue Version 1.6) kann ich nun nach verschiendene Möglichkeiten suchen:

"$Acht$" sucht alle Objekte, die "acht" oder "Acht" enthält.

Beim Einsatz der Platzhalten (Regex) werden nun auch die Sonderzeichen ( ) ` * [ ] ? { } + korrekt beachtet. Also kann ich nach "(Acht$" suchen lassen und bekomme alle Objekte, die mit "(Acht" oder ("acht" beginnen.

Direkter Link für Version 1.6: Download des Javascripts »FindByName.jsx«

 

P. S. Schleifen sind in Javascript für AI, IND und PS ein Problem. Sie laufen rund 10 mal langsamer ab, als in QuarkXPress oder HTML (Safari). 

 

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