Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Place images from sub folders

Return to Member Forum

  • Author
    Posts
    • #62413

      Hello,

      I have a bunch of images in different subfolders within a main folder, I am looking for a javascript to place them all in one document. Is this possible? I have figured out how to select multiple files in one folder, just not all files from the top level folder.

      Also, with regard to the actual placement. I have manged to work out how to place the same file multiple times but cannot figure out the repeat loop to go through each file place that one and then move onto the next.

      I have most of the script I am working on done, but its on my laptop which I left at work. I will post it tomorrow with a full description as I am sure it could do with some serious tweaking/trimming. But if anyone could help with the above in the meantime it would be greatly apprieciated!

      Thanks in advance!

    • #62414

      If you have the general framework in place to load all files from a certain folder, all you need is to do is to write a getFiles command to get just folders. From memory:

      var folderList = Folder.myDocuments.getFiles(function(item) { return item instanceof Folder; });

      The function will return 'true' for all subfolders in the path, and so the array folderList will contain a list of these. Then you can loop over the items in folderList and run the One Folder To Place Them All portion of your script on each.

    • #62417

      Hello

      I think I may have oversold myself there! Below is the script as it currently stands. It takes a single file and repeats placing it x ammount of times on an A3 page. After it each placement it checks to see how much space is left on the page and then, if required, adds a new page and starts again.

      It's my first attempt at javascript, so I dont know if its a bit too verbose! I have had to retype it as it wouldn't paste correctly! So please excuse any spelling errors!

      Could you please show me how to integrate the above in the script and how to alter the loop correctly.

      Thanks for help so far!


      var myDoc = app.documents.add();

      myDoc.documentPreferences.pageHeight = 297;

      myDoc.documentPreferences.pageWidth = 420;

      var pagHeight = myDoc.documentPreferences.pageHeight;

      var myY1 = 10;

      var myX1 = 10;

      var myY2 = 20;

      var myX2 = 20;

      var myPage = app.activeWindow.activePage;

      var aFile = new File(“Path to my image”);


      for(var i = 0; i < 20, i++){

      //Make frame and place graphic

      var myFrame = myPage.rectangles.add();

      myFrame.geometricBounds = [myY1,myX1,myY2,myX2];

      myFrame.contentType = ContentType.GRAPHIC_TYPE;

      myFrame.place(aFile);

      myFrame.fit(FitOptions.FrameToContent);

      //Get new gb references – my use some of this at a later date!

      var myGb = myFrame.geometricBounds;

      var xcoord = myGb[1];

      var xcoord = myGb[0];

      var frameWidth = myGb[3] – myGb[1];

      var frameHeight = myGb[2] – myGb[0];


      if(myGb[2] >= pagHeight – frameHeight){

      var myPage = myDoc.pages.add();

      var myY1 = 10;

      var myX1 = 10;

      var myY2 = 20;

      var myX2 = 20;

      }else{

      var myY1 = myY1 + (frameHeight + 3);

      var myY2 = myY1 + frameHeight;

      }

      }

    • #62426

      Thanks for pointing me in the right direction, I have figured it out now! Works great.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
Forum Ads