6 Replies Latest reply on Jul 11, 2016 1:18 AM by Kai Rübsamen

    group object figure caption text frame size change

    Level 1

      I need to change the figure caption text frame size based on the figure width in a grouped objects

      How to do this please advice.

        • 1. Re: group object figure caption text frame size change
          Kai Rübsamen Adobe Community Professional

          Where is your visual example and your code tryout?

          • 2. Re: group object figure caption text frame size change
            Level 1

            Capture.PNG

                var myDoc = app.activeDocument;

                var myGroup =  myDoc.groups

                for (var i =0;i<myGroup.length;i++)

                    {

                        var myname = myGroup[i].name;

             

                                    for (var j= 0;j<myGroup[i].pageItems.length;j++)

                                    {

                                              

                                                var Bound = myGroup[i].pageItems[j].geometricBounds;

                                                var height = Bound[2] - Bound[0];

                                                var width = Bound[3] - Bound[1];

                                              //  $.writeln (width )

                                            change_width = 240;

             

             

                                                

                                             if (myGroup[i].pageItems[j] == "[object TextFrame]")

                                                {

                                      app.select(myGroup[i].pageItems[j])      

                                     myStoreBounds = myGroup[i].pageItems[j].geometricBounds  

                                    app.selection[0].geometricBounds = [myStoreBounds[0], myStoreBounds[1], myStoreBounds[2], myStoreBounds[1]+width ]

                                    app.selection[0].fit(FitOptions.frameToContent);

                                    app.select(myGroup[i].allPageItems);

                                    myDoc.align (app.selection, AlignOptions.HORIZONTAL_CENTERS)

            • 3. Re: group object figure caption text frame size change
              Kai Rübsamen Adobe Community Professional

              Your informations and the code are not accurate! > Some parentheses are missing, expand the textframe 240 or to the width of the corresponding image?

               

              However: While fit to content works in the UI, it expands the caption frame in my test to the right. So I decide to write a own function for the fitting.

               

              main();
              
              function main() {
              
              var curDoc = app.activeDocument;
              var allGroups =  curDoc.groups;
              
              for (var i = 0; i < allGroups.length; i++) {
                var curGroup = allGroups[i];
                var pItems = curGroup.pageItems;
                if (pItems.length != 2) { continue; }
                for (var j = 0; j < pItems.length; j++) {
                  var curItem = pItems[j].getElements()[0];
                  var constrName = curItem.constructor.name;
                  if (constrName == "Rectangle") {
                    var rect = curItem;
                  }
                  else if (constrName == "TextFrame") {
                    var tf = curItem;
                  }
                }
                var rectGB = rect.geometricBounds;
                var tfGB = tf.geometricBounds;
                tfGB[1] = rectGB[1];
                tfGB[3] = rectGB[3];
                tfGB[2] = tfGB[2] + 20;
                tf.geometricBounds = tfGB;
                fitFrame(tf);
              }
              
              function fitFrame(aFrame) { 
                var lastBaseLine = aFrame.lines[-1].baseline; 
                var b = aFrame.geometricBounds; 
                aFrame.geometricBounds = [b[0], b[1], lastBaseLine, b[3]]; 
              } 
              }
              

               

              Note: The script will check, if there are two page items in the group. It will not check, if those two items are textframe and rectangle, it assumes that it is correct.

               

              Kai

              • 4. Re: group object figure caption text frame size change
                Level 1

                Thank you so much. You are the lifesaver

                • 5. Re: group object figure caption text frame size change
                  Level 1

                  I need to move the caption image right side of the image like below

                  Capture.PNG

                  How to do this

                  • 6. Re: group object figure caption text frame size change
                    Kai Rübsamen Adobe Community Professional

                    Feel free, to make a suggestion ;-)

                     

                    How would you do it in the UI? Note the steps and try to script it!