Skip to main content
Participating Frequently
March 10, 2014
Answered

Setting opacity in a button object (InDesign CC Mac)

  • March 10, 2014
  • 2 replies
  • 1340 views

Hello everyone.

I have some code that looks like this:

  var TheButton = ThePage.buttons.add({geometricBounds:[Top, Lef, Bot, Rgt], opacity: .2, name:"EMailButton" + n});
  
    with(TheButton)
    {
       bottomLeftCornerOption  = CornerOptions.ROUNDED_CORNER;
       bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;
       topLeftCornerOption = CornerOptions.ROUNDED_CORNER;
       topRightCornerOption= CornerOptions.ROUNDED_CORNER;
      
       name  = EMailList;
       label = EMailList;
      
      fillColor = gButtonFillColor;
     

      opacity = 20;
      
       
    }

Theh problem is in the final line.  I am trying to adjust the opacity of the fill in this object but the method I am using is not working.  I have looked all over  for the correct syntax for adjusting the fill color opacity and I cannot find an example of code, nor does the documentation seem to address this issue,

Can anyone tell me how to adjust my opacity or tell me where to look for finding out that information? 

I would greatly appreciate any help this forum could give me.

R,

John

This topic has been closed for replies.
Correct answer Laubender

@John – here just an example for adding one button with transparency set to 20% in every state with some of your properties. Others set to  distinct values so that this example will work:

//Just an example:

var myButtonGeoBounds = [0,0,10,50];

var myFillColor = "Magenta";

var myButtonProperties = {

    geometricBounds: myButtonGeoBounds,

    name:"EMailButton",

    label:"EMailButton",

    bottomLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    bottomRightCornerOption:CornerOptions.ROUNDED_CORNER,

    topLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    topRightCornerOption:CornerOptions.ROUNDED_CORNER,

    fillColor: myFillColor

    };

var myNewButton = app.documents[0].pages[0].buttons.add();

myNewButton.properties = myButtonProperties;

//In case your new button will have different states and all states should have a opacity of 20%:

for(var n=0;n<myNewButton.states.length;n++){

    myNewButton.states.groups[0].transparencySettings.blendingSettings.opacity = 20;

    };

Uwe

2 replies

LaubenderCorrect answer
Brainiac
March 11, 2014

@John – here just an example for adding one button with transparency set to 20% in every state with some of your properties. Others set to  distinct values so that this example will work:

//Just an example:

var myButtonGeoBounds = [0,0,10,50];

var myFillColor = "Magenta";

var myButtonProperties = {

    geometricBounds: myButtonGeoBounds,

    name:"EMailButton",

    label:"EMailButton",

    bottomLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    bottomRightCornerOption:CornerOptions.ROUNDED_CORNER,

    topLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    topRightCornerOption:CornerOptions.ROUNDED_CORNER,

    fillColor: myFillColor

    };

var myNewButton = app.documents[0].pages[0].buttons.add();

myNewButton.properties = myButtonProperties;

//In case your new button will have different states and all states should have a opacity of 20%:

for(var n=0;n<myNewButton.states.length;n++){

    myNewButton.states.groups[0].transparencySettings.blendingSettings.opacity = 20;

    };

Uwe

Trevor:
Brainiac
March 11, 2014

good explanation Uwe

Jump_Over
Brainiac
March 10, 2014

Hi,

use in this line:

//...

fillTransparencySettings.blendingSettings.opacity = 20;

//...

Jarek

Participating Frequently
March 10, 2014

Hello Jarek.  Thanks for yur reply.

I have been using this code to create the buttons:

for(var n = 0; n < EMailCount; n++)
{
    var TheButton = ThePage.buttons.add({geometricBounds:[Top, Lef, Bot, Rgt], name:"EMailButton" + n});
  
    with(TheButton)
    {
       bottomLeftCornerOption  = CornerOptions.ROUNDED_CORNER;
       bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;
       topLeftCornerOption = CornerOptions.ROUNDED_CORNER;
       topRightCornerOption= CornerOptions.ROUNDED_CORNER;
      
       name  = EMailList;
       label = EMailList;
      
      fillColor = gButtonFillColor;  //  Makes the fill ccolor RGB 255,0,0,
     
     
     
      fillTransparencySettings.blendingSettings.opacity = 90; 
      //contentTransparencySettings.blendingSettings.opacity = 90;
      //transparencySettings.blendingSettings.opacity = 90;     
       
    }

Please note that I have tried fillTransparencySettings. contentTransparencySettings and transparencySettings, each by themselves and all three together and it has made no difference.  The fill color remains as ruby red as a bowl of cherries.

So I am still doing something wrong.

R,

John

Brainiac
March 11, 2014

I would just apply an object style which works on buttons and will apply the opacity correctly.

I don't know why you can set the opacity of a button directly, it smell of a bug to me and if someone is feeling saintly they can report it.

Trevor


@Trevor – yes. Sounds like a bug. But after inspecting the issue, I think there is no bug.

Let's skin a Button object a bit:

A button consists of one or up to three state objects.

Every state object cannot exist without having at least one group object that would itself consist  at least of one pageItem.

If we inspect the first group item of the first state of a selected button where transparency is applied through the UI (example: Opacity 20%) we get the following result:

app.selection[0].states[0].groups[0].transparencySettings.blendingSettings.opacity;

//Result 20

Uwe