Copy link to clipboard
Copied
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
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
...
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
That sounds like it could work yes.
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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:
after running the script only Shape-B-6 is hidden, but the others are visible:
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I think CS6 big deals were play actions as you mentioned and executeMenuCommands
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I get this error.
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.
without the select command, it changes the visibilty of both without issue.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now