Skip to main content
Known Participant
June 30, 2025
Answered

Set visibility and select sublayers via CSV

  • June 30, 2025
  • 1 reply
  • 643 views

Hey All,

  I've previously asked this with objects and it works, but I have since realized that layers & sublayers are the better way for me to do this as I need to create clipping masks using the selections. I'm using Illustrator CS6 and a mac.

I need to figure out how to load and select a specific column from the CSV to set visibility of and select specific sublayers. 

CSV File: printfile.csv
For artboard Front:
-Show only the sublayers found in the csv column “frontVisible” , each of the sublayers are listed in a cell  separated by a comma ,
-Once visibility is set, I need to select 1st & 2nd array items. I will run a resize script below from Jduncan and then I would like to select all of the visible layers in the artboard so I can create a clipping mask. 

I've tried a few different ways to load the data from the csv and I am doing something wrong because it does not work. here is one that I have tried. 

function select () {
var doc = app.activeDocument;
var outlinesFrame = app.activeDocument.layers.getByName("frontVisible");
var outlinesArray = outlinesFrame.contents.split(/,/g);
for(i=0;i<len;i++)
{
   lay= app.activeDocument.layers.getByName("frontVisible");
   lay.hasSelectedArtwork=true;  
    }
}
select();

 

Any help would be appreciated.
Thanks!

Correct answer sttk3

This is the whole thing I want to do, but I have the harder ones sorted now, its just the initial selection that I'm trying to determine if it can be done with layers & an array or not.

So there are four different artboards but the process is close the the same for each. 
As an example, here is the process I was thinking of:
CSV File: printfile . csv
For artboard Front:
-Show only the sublayers found in the csv column “frontVisible” , an array separated by a “;”

-Select all active layers

-Run resize & align script on specific layers ---DONE
-Create a clipping mask with the top object ---DONE
-for Sidepanels layer, use csv data from columns sidepanelColour, sidepanelStrokeWeight, sidepanelStrokeColour to adjust the layer if not blank (not that big of a deal to be scripted, I can just do this before running the variables)
-use variables from the csv to assign font colour and stroke to the variable text (not that big of a deal to be scripted, I can just do this before running the variables)
-rescale artboard to fit art --done
-rotate everything 90 degrees -- done
-save a copy as a pdf, rbg 1998 colour, preserve spot colours --- done


Thank you for your response. Now I will provide you with a part that may be useful. This is not a script that will directly generate the result you expect after execution, but it will work as an example of the operation you want to do.

// unlock all locked object
app.executeMenuCommand('unlockAll') ;

// show all hidden object
app.executeMenuCommand('showAll') ;

// select all editable object
app.executeMenuCommand('selectall') ;


// get sublayers and make them editable
var doc = app.activeDocument ;
var frontVisibleLayer = doc.layers.getByName('frontVisible') ;

var frontVisibleContents = 'layer 1;layer 2' ;
var frontVisibleSublayerNames = frontVisibleContents.split(';') ;
for(var i = 0, len = frontVisibleSublayerNames.length ; i < len ; i++) {
  var currentSublayer = frontVisibleLayer.layers.getByName(frontVisibleSublayerNames[i]) ;

  // make a sublayer editable
  currentSublayer.locked = false ;
  currentSublayer.visible = true ;
}

1 reply

Known Participant
July 4, 2025

Is this something that just isn't possible via CSV & sublayers?

Legend
July 6, 2025

To answer your question, we first need to clarify what you finally want to do. It seems that you want to create a clipping mask, which of the following is your wish?

 

  1. Object > Clipping Mask > Make
  2. Layers Panel > Make Clipping Mask
Known Participant
July 6, 2025

Object-Clipping Mask-Make is what I plan to use if I can get this working correctly.

my end goal is to use this script along with data variables.

The reason the object level script isn't working is because in order to get the script to read the labels, they have to be visible, but then I can't get the clipping masks to work because of the labels.