Highlighted

Control Layer Visibility with Variables?

New Here ,
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

332

Likes

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

Control Layer Visibility with Variables?

New Here ,
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

333

Likes

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
Apr 06, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Apr 06, 2020 2
New Here ,
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. 😉 

Likes

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
Reply
Loading...
Apr 07, 2020 0
Adobe Community Professional ,
Apr 07, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Apr 07, 2020 0
Contributor ,
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;

}

Likes

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
Reply
Loading...
Apr 08, 2020 0
Contributor ,
Apr 08, 2020

Copy link to clipboard

Copied

IDLE-Task-Layer-Visibility.gif

 

Likes

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
Reply
Loading...
Apr 08, 2020 0