Help creating a loop
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Help creating a loop
- This topic has 9 replies, 3 voices, and was last updated 6 years, 5 months ago by Peter Kahrel.
-
AuthorPosts
-
-
October 16, 2017 at 1:09 am #98917Morgan WaageMember
I have this code for placing images in an article.
var myImg01 = new File(‘~/Desktop/Folder01/img01.jpg’);
var myImg02 = new File(‘~/Desktop/Folder01/img02.jpg’);
var myImg03 = new File(‘~/Desktop/Folder01/img03.jpg’);
var myImg04 = new File(‘~/Desktop/Folder01/img04.jpg’);var myDoc = app.activeDocument;
myDoc.pages[11].rectangles[0].place(myImg01, false);
myDoc.pages[12].rectangles[0].place(myImg02, false);
myDoc.pages[12].rectangles[1].place(myImg03, false);
myDoc.pages[13].rectangles[0].place(myImg04, false);Can someone please show me how I could make this into a loop?
-
October 16, 2017 at 10:58 am #98950Peter KahrelParticipant
How many images are there to place? And how do you know that 2 and 3 are on one page, and 1 and 4 not?
-
October 16, 2017 at 12:15 pm #98986Morgan WaageMember
It is part of a template that I have made for a 3 page article with 4 images.
Page 12 in the magazine is the first article and it contains one image placeholder. Page 13 contains two placeholders and page 14 contains one placeholder.I intend to expand the script later, so my next question would probably be how do I make the loop go through multiple folders ;)
-
October 16, 2017 at 3:11 pm #99013Peter KahrelParticipant
If you have four images I wouldn’t bother with a loop.
> I intend to expand the script later, so my next question would probably be how do I make the loop go through multiple folders
That’s a long and non-trivial story. . .
-
October 17, 2017 at 2:39 am #99038Morgan WaageMember
Well, I am only trying to break it down to more manageable chunks for me as I am learning a little about scripting in InDesign.
What I am really after is a script that builds the whole 80 page magazine with just one click.
I actually need a loop that places approximately 60 images at specific spots in 10 articles. I thought that if I kept it simple I would learn more and maybe be able to expand it on my own.
-
October 18, 2017 at 6:39 am #99071Peter KahrelParticipant
If you’re going to place images using a loop, you have to know beforehand where those images should be placed. For instance, image 1 on p. 10, image 2 on p. 11, image 3 on p. 12, etc. Or images go to rectangles named after the images on the Layers panel. E.g. img01.jpg is placed in myDoc.rectangles.item(‘img01’), img02.jpg in myDoc.rectangles.item(‘img02’), etc. The placement that you gave in your first post:
myDoc.pages[11].rectangles[0].place(myImg01, false);
myDoc.pages[12].rectangles[0].place(myImg02, false);
myDoc.pages[12].rectangles[1].place(myImg03, false);
myDoc.pages[13].rectangles[0].place(myImg04, false);is (probably) not predicatable and/or consistent: how do you know which images are placed on which rectangle on which page?
P.
-
October 18, 2017 at 9:43 am #99078Peter KahrelParticipant
Take a look at this script:
https://kasyan.ho.com.ua/place_images.html
It shows how to place images using a loop and how to get files from folders and subfolders. It’s unlikely to do exactly what you you’re after, but there’s enough there to give you ideas and to keep you busy for a while :)
-
October 18, 2017 at 11:21 am #99081Morgan WaageMember
Great! Thanks. I’ll check it out.
-
October 26, 2017 at 12:33 am #99229Michael AngeloMember
Hi Peter,
Your path “https://kasyan.ho.com.ua/place_images.html” doesn’t exist. Please provide one, I badly needed this script too. Thanks.
-
October 26, 2017 at 1:22 am #99230Peter KahrelParticipant
Maybe look around here: https://kasyan.ho.com.ua/scripts_by_categories.html
This is not my web site, it’s Kasyan Servetsky’s. If you can’t find what you’re looking for, write to him, his contact address is on his web site.
-
-
AuthorPosts
- You must be logged in to reply to this topic.