Copy link to clipboard
Copied
I am trying to write the script using chatgpt, and so far, although with difficulty, I have managed to insert as I need , the images in the specific pages. Now the problem is to scale the image in the frame of which I have specified size and position.
What function to use?
Thanks
// Create an instance of the text file with the settings
var settingsFile = new File("I:/settings.txt");
// Check if the text file exists
if (settingsFile.exists) {
// Open the file in read mode
settingsFile.open("r");
// Read the folder path from the text file
var folderPath = settingsFile.readln();
// Read the pages from the text file
var pages = settingsFile.readln();
// Close the file
settingsFile.close();
// Split the pages string into an array of page numbers
var myPages = pages.split(",");
// Get all the files in the selected folder
var myImages = new Folder(folderPath).getFiles();
// Get the current document
var myDocument = app.activeDocument;
// Iterate through each image in the selected folder
for (var i = 0; i < myImages.length; i++) {
// Get the file name
var fileName = myImages[i].name;
// Check if the file extension is .jpg, .jpeg or .png (you can add more extensions if necessary)
if (fileName.match(/\.(jpg|jpeg|png)$/i)) {
// Get the correct page
var pageNum = parseInt(myPages[i]) - 1;
if (pageNum >= 0 && pageNum < myDocument.pages.length) {
var myPage = myDocument.pages.item(pageNum);
} else {
continue;
}
// Calculate the coordinates of the four corners of the rectangle based on the specified dimensions and the position of the reference point
var rectangleWidth = 187.1;
var rectangleHeight = 196.9;
var rectangleX = 331.812 - (rectangleWidth / 2);
var rectangleY = 111.125 - (rectangleHeight / 2);
// Create a new image frame with the specified dimensions and position
var myRectangle = myPage.rectangles.add({
geometricBounds: [rectangleY, rectangleX, rectangleY + rectangleHeight, rectangleX + rectangleWidth]
});
// Assign the image to the frame
var myImage = myRectangle.place(myImages[i])[0];
// Scale the image to fit the rectangle
myImage.fit(FitOptions.centerContent);
}
}
}
Nice that GPT could help but what is even better is actually looking at the doc:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Image.html
You will find appropriate constants for fitting.
Copy link to clipboard
Copied
Nice that GPT could help but what is even better is actually looking at the doc:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Image.html
You will find appropriate constants for fitting.
Copy link to clipboard
Copied
Thank you! Solved...thanks for the link, I have been looking for it for a very long time, in fact I suggested him to use one of the functions and now it is ok! CGPT apologized for not using it before, and thanked me! ajhaha! mythical
Copy link to clipboard
Copied
I am trying to write the script using chatgpt...
<fx Kosh> And so it begins. </fx>
Copy link to clipboard
Copied
Let's get used to it @James Gifford—NitroPress 😉
Copy link to clipboard
Copied
I reserve the right to lose my temper, once, the first time a newcomer insists that we are wrong because Chatifer must be right. 😄
Copy link to clipboard
Copied
Perhaps I have somehow offended someone?
All I said was to try one of the many tools on the web, perhaps the most interesting one right now, to help me solve a problem...
Copy link to clipboard
Copied
No, put your mind at rest. You are talking to a community with mixed feelings regarding ChatGPT because, on one side, some people see this as a replacement for scripters and feel threatened; on the other side, we have to learn how to make a productive companion out of ChatGPT. You did nothing wrong, it's just the community learning to tame its concerns 🙂
Copy link to clipboard
Copied
I disagree — as one of the least abled scripters here, and thus in no way challenged or threatened by this issue, I still have deep reservations about getting complex, niche technical answers from something 'with all the books but none of the learning.'
My dark humor was meant to mark what surely will be a rising tide of novice users who don't come here and ask a sensible question, but bring ChatGPT's solution here for evaluation and correction... a pretty fair misdirection and waste of valuable time for all concerned.
No darts on the OP, here; I think his intentions were good. But at least a traditional search leads to real expertise, and more importantly, context... not just a disconnected 'answer' that leaves the user with no alternative but to go ask the question/source s/he should have been directed to in the first place. "Forty-Two!" only goes so far, as we all know.
Copy link to clipboard
Copied
I can see your points.
Copy link to clipboard
Copied
To clarify and sum up: a regular search would take the user to a place to find the answer, either with plenty of information (such as Adobe Help) or interactive interpretation and guidance, as here.
ChatGPT says, "Here's the answer." Emphasis on that period. And with something as complex as ID task scripting, it may not be a complete or even accurate answer... but there's no path to follow up and correct it. The answer may be dazzlingly "correct"... but completely wrong.
Not a good thing. Not for this, and not for many things for which I have seen ChatGPT pop up in Messiah robes. (For one thing, go count the complete-trash insta-books on Amazon!)
Copy link to clipboard
Copied
I understand the classic scaremongering and and detractors in the face of technologies that are absolutely disruptive and that are ready quickly to challenge the paradigms of work and modus operandi of almost all of us, but history shows how inherent this is now in the very history and evolution of man. That is not to say that the process of "integrating" such algorithms into economic and cultural society, will not go through criticism, adjustments, hardliners, detractors, limitations and regulations, this too, rest assured is normal and will happen.
The first thing I did is to look on the adobe site for the page related to help on scripting, but I couldn't find it, maybe I looked wrong, but it was the first thing I did.
By reading the chatgpt script, learning how to ask, understanding how it goes wrong, I also learned in this little experience. Even I had to learn some code and point out some mistakes to him. From a "learning" perspective, it doesn't seem bad for someone like me who would have maybe taken days to write the first couple of lines of code.