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

group object figure caption text frame size change

Engaged ,
Jul 07, 2016 Jul 07, 2016

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.

TOPICS
Scripting
823
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

Enthusiast , Jul 08, 2016 Jul 08, 2016

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;

  var pItems = curGroup.pageItems;

  if (

...
Translate
Enthusiast ,
Jul 07, 2016 Jul 07, 2016

Where is your visual example and your code tryout?

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
Engaged ,
Jul 07, 2016 Jul 07, 2016

Capture.PNG

    var myDoc = app.activeDocument;

    var myGroup =  myDoc.groups

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

        {

            var myname = myGroup.name;

 

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

                        {

                                  

                                    var Bound = myGroup.pageItems.geometricBounds;

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

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

                                  //  $.writeln (width )

                                change_width = 240;

                                    

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

                                    {

                          app.select(myGroup.pageItems)      

                         myStoreBounds = myGroup.pageItems.geometricBounds  

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

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

                        app.select(myGroup.allPageItems);

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

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
Enthusiast ,
Jul 08, 2016 Jul 08, 2016

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;

  var pItems = curGroup.pageItems;

  if (pItems.length != 2) { continue; }

  for (var j = 0; j < pItems.length; j++) {

    var curItem = pItems.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

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
Engaged ,
Jul 08, 2016 Jul 08, 2016

Thank you so much. You are the lifesaver

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
Engaged ,
Jul 10, 2016 Jul 10, 2016

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

Capture.PNG

How to do this

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
Enthusiast ,
Jul 11, 2016 Jul 11, 2016
LATEST

Feel free, to make a suggestion 😉

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

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