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

Script to scale text frames based on certain paragraph style ( page range )

Engaged ,
Dec 21, 2023 Dec 21, 2023

Hi

I have an indesign document that contains multiple text frames

some of these text frames have paragraph style 1 and some have paragraph style 2

Is there a script to scale text frames based on paragraph style 1 only not all text frames

and so on  text frames based on paragraph style 2 !!

and I want that script that apply on certain pages ( ex : from page 50 to 100 only ) Not all document pages 

Thanks

 

 

TOPICS
Scripting
1.2K
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

Community Expert , Dec 22, 2023 Dec 22, 2023

Ok, here you go:

 

function getData () {
  // Create a dialog
  var myDialog = new Window("dialog", "Scale Text Frames");
    myDialog.orientation = "column";
    myDialog.alignChildren = "left";

  // Function to get paragraph styles
  function getParagraphStyles() {
    var styles = app.activeDocument.paragraphStyles;
    var styleNames = []; // Default "None" style

    for (var i = 1; i < styles.length; i++) {
    styleNames.push(styles[i].name);
    }

    return styleNames;
  }

  // Parag
...
Translate
Engaged ,
Dec 21, 2023 Dec 21, 2023

Any Help Here

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 ,
Dec 21, 2023 Dec 21, 2023

Amy help here !!!!!!!!!!!!!!!

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
Community Expert ,
Dec 22, 2023 Dec 22, 2023

The purpose of this forum is to help people write their own scripts, it's not a market place or somewhere where you can expect people to do your work for you. A working script is sometimes provided, ususally by a script writer who got intrigued in a problem.

 

and I want that script that apply on certain pages

 

may not be the right way to enthuse people, and posting three reminders in a day with exclamation points doesn't help.

 

Another thing is that  your request isn't clear:

 

"Is there a script to scale text frames based on paragraph style 1 only not all text frames and so on text frames based on paragraph style 2 !!"

 

The last part is unclear: 'and so on text frames based on paragraph style 2'. 

 

Also, scaled up or down? Where is the percentafe in that text. Or is the percentage part of the style name?

 

So the way to go about it is to write an outline what you're after. Provide all details. Read it back to make sure it's clear. Screen shots are useful.

 

If no-one reports that a script exists, maybe offer a fee for writing the script.

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 ,
Dec 22, 2023 Dec 22, 2023

I asked chat gpt for this code , answered with this code but it doesn't work for me , Nothing changed

Can you help me ?

----------------------------------------

// Create a dialog
var myDialog = new Window("dialog", "Scale Text Frames");
myDialog.orientation = "column";
myDialog.alignChildren = "left";

// Function to get paragraph styles
function getParagraphStyles() {
var styles = app.activeDocument.paragraphStyles;
var styleNames = ["(None)"]; // Default "None" style

for (var i = 0; i < styles.length; i++) {
styleNames.push(styles[i].name);
}

return styleNames;
}

// Paragraph Style Dropdown
var stylePanel = myDialog.add("panel");
stylePanel.text = "Paragraph Style:";
var styleDropdown = stylePanel.add("dropdownlist", undefined, getParagraphStyles());
styleDropdown.selection = 0;

// Page Range Input
var pageRangePanel = myDialog.add("panel");
pageRangePanel.text = "Page Range (e.g., 1-5):";
var pageRangeInput = pageRangePanel.add("edittext");
pageRangeInput.text = "1-10";

// Scale Factor Input
var scalePanel = myDialog.add("panel");
scalePanel.text = "Scale Factor (%):";
var scaleFactorInput = scalePanel.add("edittext");
scaleFactorInput.text = "150";

// OK and Cancel Buttons
var buttonGroup = myDialog.add("group");
var okButton = buttonGroup.add("button", undefined, "OK");
var cancelButton = buttonGroup.add("button", undefined, "Cancel");

okButton.onClick = function () {
var selectedStyle = styleDropdown.selection.text;
var pageRange = pageRangeInput.text;
var scaleFactor = parseFloat(scaleFactorInput.text) / 100;

if (!selectedStyle || selectedStyle === "(None)") {
alert("Please select a valid paragraph style.");
return;
}

if (!pageRange.match(/^\d+-\d+$/)) {
alert("Invalid page range format. Use 'start-end', e.g., '1-5'.");
return;
}

var startPage = parseInt(pageRange.split("-")[0]);
var endPage = parseInt(pageRange.split("-")[1]);

// Your scaling logic here
// (use selectedStyle, startPage, endPage, and scaleFactor)

myDialog.close();
};

cancelButton.onClick = function () {
myDialog.close();
};

// Show the dialog
myDialog.show();

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
Community Expert ,
Dec 22, 2023 Dec 22, 2023

Well, the script has this line:

 

// Your scaling logic here

 

But there isn't any scaling logic. Also, this script asks you to input a factor, but I was under the impression that the factor could be derived from the frame content or the used paragraph style's name.

 

So, scaling up or down? And where's the reference point? Top left, bottom right? Should the text size scale as well? ChatGPT may give you a working script if you specify all that.

 

ChatGPT is like humans in this respect: what you don't ask you don't get. So tell us what you want.

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 ,
Dec 22, 2023 Dec 22, 2023

I entered these informations when running code in indesign

made scaling 70 %

I want scaling from the center point only

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
Community Expert ,
Dec 22, 2023 Dec 22, 2023

Ok, here you go:

 

function getData () {
  // Create a dialog
  var myDialog = new Window("dialog", "Scale Text Frames");
    myDialog.orientation = "column";
    myDialog.alignChildren = "left";

  // Function to get paragraph styles
  function getParagraphStyles() {
    var styles = app.activeDocument.paragraphStyles;
    var styleNames = []; // Default "None" style

    for (var i = 1; i < styles.length; i++) {
    styleNames.push(styles[i].name);
    }

    return styleNames;
  }

  // Paragraph Style Dropdown
  var stylePanel = myDialog.add("panel");
    stylePanel.text = "Paragraph Style:";
  var styleDropdown = stylePanel.add("dropdownlist", undefined, getParagraphStyles());
    styleDropdown.selection = 0;

  // Page Range Input
  var pageRangePanel = myDialog.add("panel");
    pageRangePanel.text = "Page Range (e.g., 1-5):";
    var pageRangeInput = pageRangePanel.add("edittext");
    pageRangeInput.text = "2-3";

  // Scale Factor Input
  var scalePanel = myDialog.add("panel");
    scalePanel.text = "Scale Factor (%):";
    var scaleFactorInput = scalePanel.add("edittext");
    scaleFactorInput.text = "150";

  // OK and Cancel Buttons
  var buttonGroup = myDialog.add("group");
    var okButton = buttonGroup.add("button", undefined, "OK");
    var cancelButton = buttonGroup.add("button", undefined, "Cancel");

  pageRangeInput.onDeactivate = function () {
    if (!/^\d+-\d+$/.test (this.text)) {
      alert("Invalid page range format. Use 'start-end', e.g., '1-5'.");
    }
  }

  if (myDialog.show() == 2) {
    exit();
  }

  return {
    selectedStyle: styleDropdown.selection.text,
    pageRange: pageRangeInput.text,
    scaleFactor: parseFloat(scaleFactorInput.text),
  }

}


function scaleFrames (d) {
  app.windows[0].transformReferencePoint = AnchorPoint.CENTER_ANCHOR
  var startPage = parseInt(d.pageRange.split("-")[0]) - 1;
  var endPage = parseInt(d.pageRange.split("-")[1]) - 1;
  var pages = app.documents[0].pages.everyItem().getElements();
  
  function scaleFramesSub (frames) {
    for (var i = 0; i < frames.length; i++) {
      if (frames[i].paragraphs[0].appliedParagraphStyle.name == d.selectedStyle) {
        frames[i].horizontalScale = frames[i].verticalScale = d.scaleFactor;
      }
    }
  }
  
  for (var i = startPage; i <= endPage; i++) {
    scaleFramesSub (pages[i].textFrames.everyItem().getElements());
  }
}


var data = getData();
scaleFrames (data);
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 ,
Dec 22, 2023 Dec 22, 2023

Very Great thanks for you peter

Script works as a charm

Thanks

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
Community Expert ,
Dec 22, 2023 Dec 22, 2023
LATEST

Excellent, thanks for reporting back.

Please mark the answer as correct, it makes things easier to find in the forums.

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