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

Illustrator script to toggle object visibility from CSV/Data Variables

Explorer ,
Jun 12, 2025 Jun 12, 2025

My last post was probably asking too much, so instead, does anyone have a script to deal with object visibility with details coming from a CSV/Data Sets?

I will be using data variables for other informaiton in the document, like text fields, so the data wil be loaded through the data variables. I know I could set the visibilty with the spreadsheet but I have over 1000 options so instead I was hoping to just have the objectname (like Shape-F-1) as a field in the spreadsheet.

I'm using CS6.

Thanks

 

Screen Shot 2025-06-12 at 7.50.40 AM.pngScreen Shot 2025-06-12 at 7.51.07 AM.png

 

TOPICS
Scripting
720
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

correct answers 1 Correct answer

Valorous Hero , Jun 12, 2025 Jun 12, 2025

Aha, it's because of my rookie mistake. It was showing the stuff it hid!
But now, it goes through layers, only worries about the Groups, which should be faster by leaving alone the nested shape. It pre-hides all the groups in the layer, then turns on just the ones we need!
Try this:

function test () {
  var doc = app.activeDocument;
  var shapeNamesFrame = doc.textFrames.getByName("shape-names");
  var shapeNameArray = shapeNamesFrame.contents.split(/,/g);
  for (var i = 0; i < doc.layers.length; i
...
Translate
Adobe
Valorous Hero ,
Jun 12, 2025 Jun 12, 2025

This would work: have some hidden or visible text-frame which gets your shape names.
And 2nd part: a script which is activated each data-set via your Batch Action processing which finds the one text-frame containing your shape name(s) and reads the populated contents of that text-frame to obtain the name(s).
Then it would go through all the top-level layer's pageItems to hide all except whose names are determined to be matching your CSV.
Does this sound like it can work for your workflow?

 

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
Explorer ,
Jun 12, 2025 Jun 12, 2025

That sounds like it could work yes.

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
Valorous Hero ,
Jun 12, 2025 Jun 12, 2025

Ok, assuming you have this one text-box, and it is bound to your variables, and named the word "shape-names".

This is the script:

function test () {
  var doc = app.activeDocument;
  var shapeNamesFrame = doc.textFrames.getByName("shape-names");
  var shapeNameArray = shapeNamesFrame.contents.split(/,/g);
  for (var i = 0; i < shapeNameArray.length; i++) {
    var name = shapeNameArray[i];
    for (var j = 0; j < doc.layers.length; j++) {
      var layer = doc.layers[j];
      for (var k = 0; k < layer.pageItems.length; k++) {
        var pageItem = layer.pageItems[k];
        pageItem.hidden = pageItem.name === name;
      }
    }
  }
}
test();

 Stick it into the Menu Items so that your action can play it - let's see if it works!
Just ensure that this text-frame is bound to your variable and is named accordingly, and that you concatenate all your shape names with a comma (in this case).

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
Explorer ,
Jun 12, 2025 Jun 12, 2025

Thank you!

I think I'm doing something wrong with my setup because it is turning off visibility for only one. I tried it with the text and path in groups and not in groups. Do I need them to be their own layer?

This is before running the script, shapes visible, text box hidden:

Screen Shot 2025-06-12 at 2.29.54 PM.png

after running the script only Shape-B-6 is hidden, but the others are visible:
Screen Shot 2025-06-12 at 2.30.15 PM.png

 

 

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
Valorous Hero ,
Jun 12, 2025 Jun 12, 2025

Aha, it's because of my rookie mistake. It was showing the stuff it hid!
But now, it goes through layers, only worries about the Groups, which should be faster by leaving alone the nested shape. It pre-hides all the groups in the layer, then turns on just the ones we need!
Try this:

function test () {
  var doc = app.activeDocument;
  var shapeNamesFrame = doc.textFrames.getByName("shape-names");
  var shapeNameArray = shapeNamesFrame.contents.split(/,/g);
  for (var i = 0; i < doc.layers.length; i++) {
    var layer = doc.layers[i];
    for (var k = 0; k < layer.groupItems.length; k++) {
       var groupItem = layer.groupItems[k];
       groupItem.hidden = true;
    }
    for (var j = 0; j < shapeNameArray.length; j++) {
      var name = shapeNameArray[j];
      for (var k = 0; k < layer.groupItems.length; k++) {
        var groupItem = layer.groupItems[k];
        if (groupItem.name === name) {
          groupItem.hidden = false;
        }
      }
    }
  }
}
test();

  

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
Explorer ,
Jun 12, 2025 Jun 12, 2025

Oh that works great! Thank you so much. I was able to adapt it easily to my actual template.
I've tried a few different ways but haven't been able to figure it out, can this be done for a few different objects? Like in my original spreadsheet I have F-Shape and B-Shape.

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
Explorer ,
Jun 12, 2025 Jun 12, 2025

Oh wait. Just realized when walking the dog as long as I have both linked to "shape-names" they would fill up the array? I was adding a whole new variable, but I don't think I need to.

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
Valorous Hero ,
Jun 12, 2025 Jun 12, 2025

Yes, I also had this same thing happen - the walking, and the dog and the solution! True story.

So, yes I believe, your shapes simply need be as one single line of comma-delimited words.

Okay super, glad it works for you. By the way, what if, a sheik finds your services for a guap - and what if, some day you end up migrating to CC - then hopefully that one plugin called "Darty-Ai", would be of value to you! Meanwhile, you can do a lot with CS6, and with today's ChatGPT + these forums - it should be fairly unlimited for all kinds of needs, with CS6. That's because they added some powerful features which were not in CS5-, for scripting - but I already forgot what those features were. I think that's when they allowed us to run the actions via script, I think it was some kind of really big deal. Anyways, some folks have still CS4... respect!

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
Explorer ,
Jun 13, 2025 Jun 13, 2025

I'm definately working my way through my list with lots of searching to see if I can get this working how I need it, fingers crossed I can easily cross them off with this software haha

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
Community Expert ,
Jun 13, 2025 Jun 13, 2025

I think CS6 big deals were play actions as you mentioned and executeMenuCommands

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
Explorer ,
Jun 13, 2025 Jun 13, 2025

Ohhh another quesiton, how would I make the items I made visible, the current selection?

I've tried a few different scripts I've found but most don't deal with variables.

I've tried code variations using //groupItem.selected = true;//

but I'm not able to make them work with the array.

The goal is to them use this seleciton with the MatchObjects script and then as clipping mask

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
Valorous Hero ,
Jun 13, 2025 Jun 13, 2025

If you start with no selection, it should be possible to put what you tried right below the line:

groupItem.hidden = false;

groupItem.selected = true;

 

What happens when you try doing this? Ideally it should leave all the items selected.. but there could be a chance a post-process of some kind is doing its own thing whether intentionally or inadvertantly, which could negate the selection efforts.

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
Explorer ,
Jun 14, 2025 Jun 14, 2025

I get this error.

Screen Shot 2025-06-14 at 8.19.38 AM.png

The script works great until I add that line. Once I add that line, it changes the visiblity and selection of the first item in the array and then the error occurs. This is the structure after that.

Screen Shot 2025-06-14 at 8.43.42 AM.png

 

without the select command, it changes the visibilty of both without issue.

Screen Shot 2025-06-14 at 8.45.56 AM.png

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
Valorous Hero ,
Jun 14, 2025 Jun 14, 2025

Are you sure you are putting it where it should be? 

groupItem.hidden = false;

groupItem.selected = true;

 

If the item is first set to hidden = false, then it ought to be selectable and not throw any error.

 

Make sure you insert here:

        if (groupItem.name === name) {
          groupItem.hidden = false;
          groupItem.selected = true;
        }
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
Explorer ,
Jun 14, 2025 Jun 14, 2025

Yep, this is my whole code:
function test () {
var doc = app.activeDocument;
var outlinesFrame = doc.textFrames.getByName("outlines");
var outlinesArray = outlinesFrame.contents.split(/,/g);
for (var i = 0; i < doc.layers.length; i++) {
var layer = doc.layers[i];
for (var k = 0; k < layer.groupItems.length; k++) {
var groupItem = layer.groupItems[k];
groupItem.hidden = true;
}
for (var j = 0; j < outlinesArray.length; j++) {
var name = outlinesArray[j];
for (var k = 0; k < layer.groupItems.length; k++) {
var groupItem = layer.groupItems[k];
if (groupItem.name === name) {
groupItem.hidden = false;
groupItem.selected = true;

}
}
}
}
}
test();

I tried it with the text fields visible and it works, it ends up grabbing the groups instead of the objects but I can still use the Match Objects script with the groups and then I can do the clipping mask afterwards, so that should work.
I don’t know why it’s not working the other way but this workaround should work. 
THANK YOU.

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
Explorer ,
Jun 26, 2025 Jun 26, 2025
LATEST

.

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