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

Add a little height to text box in indesign?

New Here ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

Hi!

I have a big and nice script that applies height/width changes to a document based on object styles and other parameters.

But what I really need is a script that just adds a little height to a selected text box. It does not have to rely on object styles and should apply only to one box.

I'm learning to program, but have no javascript skills so far...

Is there any way to cut down the script under?

(Source: https://forums.adobe.com/thread/628574)

// setBoundsOfObjectsWithAppliedObjectStyle.jsx  

//DESCRIPTION: change the metrics of objects applied with certain object style

// 2010/02  

  

var doc = app.documents.firstItem();  

var the_operator = ['absolut', 'addieren', 'multiplizieren', 'prozentual skalieren']; 

var r = get_param(doc.objectStyles.everyItem().getElements().slice(0),  the_operator);  

var  f_objects = get_objects ( r.style);  

apply_values(f_objects, r, the_operator);  

  

  

function apply_values(the_objects, r)  

{  

    for (var i = the_objects.length - 1; i >= 0; i--)  

    {  

        var gb = the_objects.visibleBounds;  

        if (r.op == the_operator[0]) //'absolut')  

        {  

            var _y2 = (r.height != 0)  

                ? gb[0] + r.height  

                : gb[2];  

            var _x2 = (r.width != 0)  

                ? gb[1] + r.width  

                : gb[3];  

        }  

        else if (r.op == the_operator[2] || r.op == the_operator[3]) //'multiplizieren' oder 'prozentual skalieren' 

        {  

            var the_div = (r.op == the_operator[2]) //'multiplizieren') 

                ? 1 

                : 100; 

            var _y2 = (r.height != 0)  

                ? gb[0] + (gb[2]-gb[0]) * r.height/the_div  

                : gb[2];  

            var _x2 = (r.width != 0)  

                ? gb[1] + (gb[3]-gb[1]) * r.width/the_div  

                : gb[3];  

        }  

        else if (r.op == the_operator[1]) //'addieren' ) 

        { 

            var _y2 = gb[2] + r.height;  

            var _x2 = gb[3] + r.width; 

        } 

        the_objects.visibleBounds = [gb[0], gb[1],  _y2 , _x2];   

    }  

}  

  

function get_objects(a_style)  

{  

    app.findObjectPreferences = null;  

    app.findChangeObjectOptions.objectType = ObjectTypes.ALL_FRAMES_TYPE;  

    app.findObjectPreferences.appliedObjectStyles =a_style;  

    var the_result = doc.findObject();  

    app.findObjectPreferences = null;  

    return the_result;  

}  

  

function get_param(_styles, the_operator)  

{  

    var style_names = new Array;  

    //Ausklammern von '[Einfaches Raster]'  

    for (var a = 1; a < _styles.length; a++)  

        style_names.push(_styles.name);  

    var min_width = 140; 

    var field_width = 40; 

    var myDialog = app.dialogs.add({name:"Breite und Höhe von Objekten verändern"});   

    with( myDialog.dialogColumns.add())   

    {   

        with(dialogRows.add())   

        {  

            with(dialogColumns.add())   

            {   

                staticTexts.add({staticLabel:"Objektstil:",    minWidth:min_width});   

            }   

            with(dialogColumns.add())   

            {   

                var myStylesDropDown = dropdowns.add({stringList:style_names,    selectedIndex:style_names.length-1, minWidth:min_width});   

            }   

        }   

        with(dialogRows.add())   

        {   

            with(dialogRows.add())   

            {   

                with(dialogColumns.add())   

                {   

                    staticTexts.add({staticLabel:"Breite:",    minWidth:min_width});   

                }   

                with(dialogColumns.add())   

                {   

                    var myWidthTextEditbox = textEditboxes.add({editContents:"0",    minWidth:field_width});   

                }   

            }   

            with(dialogRows.add())   

            {   

                with(dialogColumns.add())   

                {   

                    staticTexts.add({staticLabel:"Höhe:",    minWidth:min_width});   

                }   

                with(dialogColumns.add())   

                {   

                    var myHeightTextEditbox = textEditboxes.add({editContents:"0",    minWidth:field_width});   

                }   

            }   

            with ( dialogRows.add () ) {   

                with(dialogColumns.add())  {                     

                staticTexts.add( {staticLabel: "Operation: ", minWidth: min_width} ); 

                } 

                with(dialogColumns.add())   

                { 

                    var radio_buttons = radiobuttonGroups.add(); 

                    with(radio_buttons) { 

                        radiobuttonControls.add({staticLabel: the_operator[0], checkedState: true, minWidth: min_width}); 

                        radiobuttonControls.add({staticLabel: the_operator[1], checkedState: false, minWidth: min_width}); 

                        radiobuttonControls.add({staticLabel: the_operator[2], checkedState: false, minWidth: min_width}); 

                        radiobuttonControls.add({staticLabel: the_operator[3], checkedState: false, minWidth: min_width}); 

                    } 

                } 

            } 

        }  

    }   

    var myResult = myDialog.show();   

    if(myResult == true)   

    {   

        var a_style = doc.objectStyles.item(myStylesDropDown.selectedIndex);   

        var a_width = Number(myWidthTextEditbox.editContents.replace(',','.'));  

        var a_height = Number(myHeightTextEditbox.editContents.replace(',','.'));  

        var a_operator = the_operator[radio_buttons.selectedButton]  

        if (isNaN (a_width))  

            a_width = 0;  

        if (isNaN (a_height))  

            a_height = 0;  

        myDialog.destroy();   

    }   

    else   

    {   

        myDialog.destroy();   

        exit();  

    }   

    return {style:a_style, width: a_width, height: a_height, op: a_operator};   

TOPICS
Scripting

Views

547

Translate

Translate

Report

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

People's Champ , Jul 06, 2016 Jul 06, 2016

var resizeItem = function(item, h) {

  const cs = CoordinateSpaces.INNER_COORDINATES,

  ap = AnchorPoint.TOP_LEFT_ANCHOR,

  rm = ResizeMethods.ADDING_CURRENT_DIMENSIONS_TO;

  item.resize  ( cs, ap, rm, [0,h] );

  }

var h = new UnitValue ( "2mm").as("pt");

resizeItem ( app.selection[0], h );

Here you are

Loic

www.ozalto.com

Votes

Translate

Translate
People's Champ ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

You have very many ways to achieve that. But if goal is to increase selection height, what could possibly a script offer more than just typing in the transformation info ?

Votes

Translate

Translate

Report

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 ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

It's part of a bigger script with many steps, so I don't want it done manually.

Votes

Translate

Translate

Report

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
People's Champ ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

ok but what do you want exaclty ?:

a) Set an explicit height

b) increase height by x units (and then from which reference point ?)

c) increase height proportionnaly (and then from which reference point ?)

Loic

Votes

Translate

Translate

Report

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 ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

Thanks for your answer. To be specific:

1. Set current height = height;

2. Set reference point top middle point.[in a 3x3 grid]. (or one of the three top points, really?)

3. Add height by x units. Do not increase proportionally.

Width is not affected.

IMAGE.jpg

Votes

Translate

Translate

Report

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
People's Champ ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

var resizeItem = function(item, h) {

  const cs = CoordinateSpaces.INNER_COORDINATES,

  ap = AnchorPoint.TOP_LEFT_ANCHOR,

  rm = ResizeMethods.ADDING_CURRENT_DIMENSIONS_TO;

  item.resize  ( cs, ap, rm, [0,h] );

  }

var h = new UnitValue ( "2mm").as("pt");

resizeItem ( app.selection[0], h );

Here you are

Loic

www.ozalto.com

Votes

Translate

Translate

Report

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 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

Hi Loic, my solution was to change the gBs, but you was a bit faster .

var changeHeight = 20;

var curSel = app.selection[0];

var gB = curSel.geometricBounds;

gB[2] = gB[2] + changeHeight;

curSel.geometricBounds = gB;

What is the benefit to use resize instead of changing the bounds? Thanks.

Kai

Votes

Translate

Translate

Report

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
People's Champ ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

Hi Kai,

Not sure one is deeply better than the other. I looked at performance, it seems delays are similar.

Possibly better not to call a method and prefer using properties as you did though for performance.

Really can't say. If I had to defend my snippet, I may advance that using UnitValue you may push wathever values.

But even then, it's easy to set measurement units to whatever.

Votes

Translate

Translate

Report

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 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

I didn’t know 'UnitValue' before. It seems that 'new' is not needed?! Pretty cool. Thanks.

Kai

Votes

Translate

Translate

Report

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
People's Champ ,
Jul 06, 2016 Jul 06, 2016

Copy link to clipboard

Copied

UnitValue object is explained in the Javascript Tool guide. It's a great tool that avoid using approximative conversion rations between units.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thanks very much for your help, guys!

Votes

Translate

Translate

Report

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