Copy link to clipboard
Copied
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
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...
Copy link to clipboard
Copied
Any Help Here
Copy link to clipboard
Copied
Amy help here !!!!!!!!!!!!!!!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Very Great thanks for you peter
Script works as a charm
Thanks
Copy link to clipboard
Copied
Excellent, thanks for reporting back.
Please mark the answer as correct, it makes things easier to find in the forums.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now