These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Drop Down that results to OCG layer turning on.

saj
Registered: Oct 15 2008
Posts: 52

Hi.

I have a drop down that has two options Hardcover and Softcover. When Hardcover is selected I would like the OCG layer for Hard Cover to appear....and the same would happen for Softcover; the Soft Cover OCG layer will appear.

I'm not sure how to connect the drop down to the OCG layer. Can someone guide me in the right direction? Thanks in advance.

Acrobat 9 Pro, Mac

thanks much.
sara

My Product Information:
Acrobat Pro 9.2, Macintosh
StevenD
Registered: Oct 6 2006
Posts: 368
Others more skilled at JavaScript may not find it so but for me scripting OCG layers is challenging. But here is something that may help. I have used these two JavaScripts in bookmarks. You could put these with buttons however.

I made two bookmarks one named "Show Front Cover" and the other "Show Back Cover". The layer names are "Page 1" and "Page 2".

I assigned the following scripts to a "Run a JavaScript" action in each bookmark instead of haveing the bookmarks go to a certain page/view.

//This is the script for the first bookmark.
function GetOCGByName(myLayerName)
{
var myOCGs = getOCGs(pageNum);
for(var i = 0; i < myOCGs.length; i++)
{
if(myOCGs[i].name == myLayerName)
return myOCGs[i];
}
return null;
}

var showPage1 = GetOCGByName("Page 1");
var showPage2 = GetOCGByName("Page 2");

showPage1.state = true;
showPage2.state = false;

//This is the script for the second bookmark.
function GetOCGByName(myLayerName)
{
var myOCGs = getOCGs(pageNum);
for(var i = 0; i < myOCGs.length; i++)
{
if(myOCGs[i].name == myLayerName)
return myOCGs[i];
}
return null;
}

var showPage1 = GetOCGByName("Page 1");
var showPage2 = GetOCGByName("Page 2");

showPage2.state = true;
showPage1.state = false;

StevenD

saj
Registered: Oct 15 2008
Posts: 52
Steven--thanks so much!!!!! I really am struggling on getting them to work together. Thank for the suggestion I'll try this.
StevenD
Registered: Oct 6 2006
Posts: 368
In my haste to get my first response posted and after getting interupted I forgot that you are using a drop down. So here is a script that works with a button. I don't really like working with combo boxes that much so I like to make drop downs with JavaScripts.

//First make the dropdown.
var myChoice = app.popUpMenuEx(
{cName:"Show Front Cover"},
{cName:"Show Back Cover"}
)

//Then do the layers function and get the names of the layers.
function GetOCGByName(myLayerName)
{
var myOCGs = getOCGs(pageNum);
for(var i = 0; i < myOCGs.length; i++)
{
if(myOCGs[i].name == myLayerName)
return myOCGs[i];
}
return null;
}var showPage1 = GetOCGByName("Page 1");
var showPage2 = GetOCGByName("Page 2");

//If the choice made is Show Front Cover then turn that layer on and the other one off.
if(myChoice === "Show Front Cover")
{
showPage1.state = true;
showPage2.state = false;
}//If the choice made is Show Back Cover then turn it on and the other one off.
if(myChoice === "Show Back Cover")
{
showPage2.state = true;
showPage1.state = false;
}

StevenD