Skip to main content
GregL2570
Participating Frequently
April 6, 2020
Question

Control Layer Visibility with Variables?

  • April 6, 2020
  • 1 reply
  • 1833 views

Does anyone know if it's possible to control layer visibiliy using a text variable? I'm trying to automate a data merge process by having the value of one specific paragraph style block control the visibility of a layer. 

This topic has been closed for replies.

1 reply

Charu Rajput
Community Expert
Community Expert
April 6, 2020

Hello, 
Setting of visiblity of layer is a boolen property as below

 

app.activeDocument.layers[0].visible = true // To make layer visible
app.activeDocument.layers[0].visible = false // To make layer invisible.

 

In your scenario, you can have work around. You can create a object like

 

var myObject = {
'patagraphContent': 'Your specific paragraph Style block',
'visibility': true // or false as you want or may be toggle.
}

 

Using this object then you can set visibility as

 

app.activeDocument.layers[0].visible =  myObject.visibility;

 

I hope this helps you.

Best regards
GregL2570
GregL2570Author
Participating Frequently
April 7, 2020

Thank you very knidly for this. It's helpful in the sense that it re-emphasizes the importantance of learning how to write javascript. I was hoping there might be a another way to toggle layer visibility based on object variables. 

 

I'm currenly working with the data merge feature to generate batches of certificates from a CSV file, and I've got everything else working perfectly. Was just hoping that I might be able to have the contents of one single text box determine which related graphic layer is visible depending on the text value. 

 

Might have to just do this manually until I learn to write code better. 😉 

brian_p_dts
Community Expert
Community Expert
April 7, 2020