Help creating a loop

Tagged: , ,

Viewing 9 reply threads
  • Author
    Posts
    • #98917
      Morgan Waage
      Member

      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?

    • #98950
      Peter Kahrel
      Participant

      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?

    • #98986
      Morgan Waage
      Member

      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 ;)

    • #99013
      Peter Kahrel
      Participant

      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. . .

    • #99038
      Morgan Waage
      Member

      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.

    • #99071
      Peter Kahrel
      Participant

      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.

    • #99078
      Peter Kahrel
      Participant

      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 :)

    • #99081
      Morgan Waage
      Member

      Great! Thanks. I’ll check it out.

    • #99229

      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.

    • #99230
      Peter Kahrel
      Participant

      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.

Viewing 9 reply threads
  • You must be logged in to reply to this topic.
>
Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo