Skip to main content
tpk1982
Legend
September 1, 2016
Answered

Change Text frame width from prompt

  • September 1, 2016
  • 1 reply
  • 764 views

Hi,

I need to change the text frame width by getting values by prompt. Tried with resize method but not able to pass the prompt value.

app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;  

app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;

var myTableParent=app.activeDocument.selection[0].parentTextFrames[0]

//~ var parentWidth = myTableParent.geometricBounds[3] - myTableParent.geometricBounds[1];

var myvaluesprompt=prompt("Please enter the desired value (IN INCHES)","");

  

myTableParent.resize( 

    CoordinateSpaces.pasteboardCoordinates, 

          CoordinateSpaces.INNER_COORDINATES,  

          AnchorPoint.TOP_LEFT_ANCHOR,  

          ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, 

          [myvaluesprompt, ResizeConstraints.KEEP_CURRENT_VALUE]  );

Please select some text in the text frame. Hope you aware i used parenttextframe.

Advance Thanks,

K

This topic has been closed for replies.
Correct answer Loic.Aigon

Hi Loic,

Initially i tested with selection of text and ran the script. It wont respond. So only i just comment that.

Please select some text in the text frame. Hope you aware i used parenttextframe. (from my OP)

Thanks,

Karthi


Hi,

so it's just a small adjustment:

var main = function() {

  var doc = app.properties.activeDocument,

  sel, nw;

  if(!doc || app.selection.length!=1) return;

  sel = app.selection[0];

  if ( sel.properties.parentStory  && !sel.properties.geometricBounds ) {

  if ( !sel.parentTextFrames.length ) {

  alert("You selected text but parent text frame is not accessible at the moment. Text must be overflowing…" );

  return;

  }

  sel  = sel.parentTextFrames[0];

  }

  var p = prompt ("Please set a new width in inches", "");

  if ( !p || !/^\d+(\.\d+)?$/.test(p) ) {

  alert("Wrong value !");

  return;

  }

  nw = new UnitValue ( p, "in" ).as("pt");

  sel.resize (

  CoordinateSpaces.INNER_COORDINATES,

  AnchorPoint.TOP_LEFT_ANCHOR, 

  ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,   

  [nw, ResizeConstraints.KEEP_CURRENT_VALUE]

  );

}

main();

1 reply

Loic.Aigon
Legend
September 1, 2016

var main = function() {

  var doc = app.properties.activeDocument,

  sel, nw;

  if(!doc || app.selection.length!=1) return;

  sel = app.selection[0];

  if ( sel.properties.parentStory || ! sel.properties.geometricBounds ) return;

  var p = prompt ("Please set a new width in inches", "");

  if ( !p || !/^\d+(\.\d+)?$/.test(p) ) {

  alert("Wrong value !");

  return;

  }

  nw = new UnitValue ( p, "in" ).as("pt");

  sel.resize (

  CoordinateSpaces.INNER_COORDINATES,

  AnchorPoint.TOP_LEFT_ANCHOR, 

  ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,   

  [nw, ResizeConstraints.KEEP_CURRENT_VALUE]

  );

}

main();

HTH

Loic

Ozalto | Productivity Oriented - Loïc Aigon

tpk1982
tpk1982Author
Legend
September 1, 2016

Thank you Loic, but if i run the script it wont did anything. It just returned.. not sure why it return without do any action

tpk1982
tpk1982Author
Legend
September 1, 2016

It run if i comment the line 8