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

Setting opacity in a button object (InDesign CC Mac)

New Here ,
Mar 10, 2014 Mar 10, 2014

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

TOPICS
Scripting
1.3K
Translate
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

correct answers 1 Correct answer

Community Expert , Mar 11, 2014 Mar 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,

    to

...
Translate
Mentor ,
Mar 10, 2014 Mar 10, 2014

Hi,

use in this line:

//...

fillTransparencySettings.blendingSettings.opacity = 20;

//...

Jarek

Translate
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
New Here ,
Mar 10, 2014 Mar 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

Translate
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
Mentor ,
Mar 10, 2014 Mar 10, 2014

Hi,

right,

this line could goes like this:

groups[0].rectangles[0].fillTransparencySettings.blendingSettings.opacity = 20;

button is more complex object than regular ones...

Jarek

Translate
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
Guru ,
Mar 11, 2014 Mar 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

Translate
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 ,
Mar 11, 2014 Mar 11, 2014

@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

Translate
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 ,
Mar 11, 2014 Mar 11, 2014

Just to demonstrate my case here some screen grabs:

1. Setting opacity through the UI:

SettingOpacity_ThroughUI.png

2. Setting opacity through script (before script)

SettingOpacity_ThroughScript_Group1ofState1_BEFORE.png

3. Setting opacity through script (after script)

SettingOpacity_ThroughScriptt_Group1ofState1_AFTER.png

Script:

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

Uwe

Translate
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 ,
Mar 11, 2014 Mar 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

Translate
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
Guru ,
Mar 11, 2014 Mar 11, 2014

good explanation Uwe

Translate
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
Mentor ,
Mar 11, 2014 Mar 11, 2014

@Uwe,

...valuable one!

Jarek

Translate
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
New Here ,
Mar 11, 2014 Mar 11, 2014
LATEST

My many thanks to all of you for sticking with me.  Uwe, your solution works like a dream and I greatly appreciate your help.  Is that two lunches I now owe you? (grin)

One final request before we close this conversation.  Uwe, you mentioned the word "inspect" in your description of what should be.  I have been looking for something like that for the last month or so and cannot find it though I know it must exist some place in some obscure tome about debugging Javascript.  Can you point me to the documentation which tells me how to use it?

TIA!

John

Translate
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