Copy link to clipboard
Copied
I have a field that exists on multiple pages. The fields name is:
032state
For example let's say it resides on page 12 and 13 (based on page index starting with 0).
I am clicking a button that looks for a specific layer within the page that the button is on. The script checks to see if the specific layer state is true or false and toggles it accordingly. What I want is the 032state field to do is....
When the specific layer ON THAT PAGE is visible the field is visible, when it is off the field is hidden.
So if I click the button on page 13 I need it to ONLY change the display state of the field on page 13.
Line 20 and line 33 is where I am stuck.
Here is my code...any help would be greatly appreciated. I'm still a newbie
var ocgSchematicArray = this.getOCGs(this.pageNum);
var getButtonName = this.getField("032wires");
var getState = this.getField("032state");
var theFieldsPage = getState.page;
// Look through all the layers on this page
for (var i = 0; i < ocgSchematicArray.length; i++) {
// Find the layer name that matches the defined wire color
if (ocgSchematicArray.name == "032 (Red) (Battery Power)") {
// If the layer is turned on...
if (ocgSchematicArray.state == true) {
// Turn the layer off
ocgSchematicArray.state = false;
// Look through the fields page numbers
for (var z = 0; z < theFieldsPage.length; z++) {
// Find the field on the right page
if (theFieldsPage
== this.pageNum) { // Only change the display of the field on this page
HERE IS WHERE I DON'T KNOW WHAT TO DO.display = display.hidden;
}
}
}
// If the layer is turned off...
else if (ocgSchematicArray.state == false) {
// Turn the layer on
ocgSchematicArray.state = true;
// Look through the fields page numbers
for (var z = 0; z < theFieldsPage.length; z++) {
// Find the field on the right page
if (theFieldsPage
== this.pageNum) { // Only change the display of the field on this page
HERE IS WHERE I DON'T KNOW WHAT TO DO.display = display.visible;
}
}
}
}
}
Try this:
getField("032state.0").display = display.hidden;
You'd refer to the other 032state button as "032state.1".
Copy link to clipboard
Copied
Try this:
getField("032state.0").display = display.hidden;
You'd refer to the other 032state button as "032state.1".
Copy link to clipboard
Copied
That does work! Thank you George_Johnson​!!
I changed it so that I didn't have to make the .0 or .1 specific....
getField("032state."+
).display = display.hidden;
getField("032state."+
).display = display.visible;
Final code....
var ocgSchematicArray = this.getOCGs(this.pageNum);
var getButtonName = this.getField("032wires");
var getState = this.getField("032state");
var theFieldsPage = getState.page;
// Look through all the layers on this page
for (var i = 0; i < ocgSchematicArray.length; i++) {
// Find the layer name that matches the defined wire color
if (ocgSchematicArray.name == "032 (Red) (Battery Power)") {
// If the layer is turned on...
if (ocgSchematicArray.state == true) {
// Turn the layer off
ocgSchematicArray.state = false;
// Look through the fields page numbers
for (var z = 0; z < theFieldsPage.length; z++) {
// Find the field on the right page
if (theFieldsPage
== this.pageNum) { // Only change the display of the field on this page
getField("032state."+
).display = display.hidden; }
}
}
// If the layer is turned off...
else if (ocgSchematicArray.state == false) {
// Turn the layer on
ocgSchematicArray.state = true;
// Look through the fields page numbers
for (var z = 0; z < theFieldsPage.length; z++) {
// Find the field on the right page
if (theFieldsPage
== this.pageNum) { // Only change the display of the field on this page
getField("032state."+
).display = display.visible; }
}
}
}
}
Thank you again for the help!! Much appreciated!
Copy link to clipboard
Copied
Although that happens to work in this case, you really should do:
getField("032state." + z).display = display.hidden;