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

Control Layer Visibility with Variables?

Explorer ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

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. 

TOPICS
Scripting

Views

1.4K

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 ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

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

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 ,
Apr 07, 2020 Apr 07, 2020

Copy link to clipboard

Copied

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. 😉 

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 ,
Apr 07, 2020 Apr 07, 2020

Copy link to clipboard

Copied

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 ,
Apr 08, 2020 Apr 08, 2020

Copy link to clipboard

Copied

#targetengine "session"

main();

function main()
{
    mySetup();
    mySnippet();
    myTeardown();
}

function mySetup()
{
}

function mySnippet()
{
    //<fragment> 
    var myIdleTask = app.idleTasks.add({name:"my_idle_task", sleep:10000});
    var onIdleEventListener = myIdleTask.addEventListener("onIdle", onIdleEventHandler, false);
    alert("Created idle task " + myIdleTask.name + "; added event listener on " + onIdleEventListener.eventType);
    //<fragment>
}

function myTeardown() {
    }

//<fragment>
function onIdleEventHandler(myIdleEvent) {

    var curLabel = "VISIBILITY";

    var  curTextFrame = getPageitemFromLabel(curLabel);
    
    if ( curTextFrame != null && curTextFrame.isValid ) {
         
         var curContent = curTextFrame.contents;
         if (curContent == "false") {
         
            app.activeDocument.layers.itemByName("Ebene 2").visible = false;
            
         } else {
             app.activeDocument.layers.itemByName("Ebene 2").visible = true;
         }
         
         return;
    }

    //Delete idle task by setting its sleep time to zero.
    myIdleEvent.parent.sleep = 0;
    alert("Nothing to do. Delete idle task.");
}
//<fragment>



// holt die entsprechenden Items von der Musterseite
function getPageitemFromLabel (curLabel) {
	
	var pageItemWithLabel = null;
	if (curLabel != null && curLabel != "" && app.documents.length > 0) {
		var allPageItems = app.activeDocument.pageItems;
		for (var i=0; i<allPageItems.length;i++) {

			var curPageItem = allPageItems[i];
			var parentName = curPageItem.parent.constructor.name;

			if (curPageItem.label == curLabel && (parentName == "Page" || parentName == "Spread" )) {
				pageItemWithLabel = curPageItem;
                  break;
			}
		}
	}
	return pageItemWithLabel;

}

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 ,
Apr 08, 2020 Apr 08, 2020

Copy link to clipboard

Copied

LATEST

IDLE-Task-Layer-Visibility.gif

 

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