10 Replies Latest reply on Mar 11, 2014 6:50 AM by NoPrevaricator

    Setting opacity in a button object (InDesign CC Mac)

    NoPrevaricator

      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[n];
             label = EMailList[n];
            
            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

        • 1. Re: Setting opacity in a button object (InDesign CC Mac)
          Jump_Over Level 5

          Hi,

           

          use in this line:

           

          //...
          fillTransparencySettings.blendingSettings.opacity = 20;
          //...
          

           

          Jarek

          • 2. Re: Setting opacity in a button object (InDesign CC Mac)
            NoPrevaricator Level 1

            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[n];
                   label = EMailList[n];
                  
                  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

            • 3. Re: Setting opacity in a button object (InDesign CC Mac)
              Jump_Over Level 5

              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

              • 4. Re: Setting opacity in a button object (InDesign CC Mac)
                Trevorׅ Adobe Community Professional

                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

                • 5. Re: Setting opacity in a button object (InDesign CC Mac)
                  Laubender Adobe Community Professional & MVP

                  @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

                  • 6. Re: Setting opacity in a button object (InDesign CC Mac)
                    Laubender Adobe Community Professional & MVP

                    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

                    • 7. Re: Setting opacity in a button object (InDesign CC Mac)
                      Laubender Adobe Community Professional & MVP

                      @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[n].groups[0].transparencySettings.blendingSettings.opacity = 20;
                          };
                      

                       

                      Uwe

                      • 9. Re: Setting opacity in a button object (InDesign CC Mac)
                        Jump_Over Level 5

                        @Uwe,

                         

                        ...valuable one!

                         

                        Jarek

                        • 10. Re: Setting opacity in a button object (InDesign CC Mac)
                          NoPrevaricator Level 1

                          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