15 Replies Latest reply on Feb 8, 2017 3:24 AM by Laubender

    Actions (like in PS/Illu) in InDesign / functions batch?

    DBLjan Level 2

      Hi there,

       

      Scripting stuff together seems like the only workaround for making InDesign do his recurring magic like a batch.
      I dont know, why these are features in Photoshop and Illustrator for decades, but not (yet?) in InDesign.

       

      But maybe you InDesigners have a smart recommendation to group recurring tasks together and execute by script/plugin?

      As Im no scripting ace, it would take for ages try and error that code together, I want to know from you how to tackle this batch of tasks…

       

      Task: Reduce the imagebox, to the extend of the used alphamask

       

      Like this: A imported TIF/PSD with a given alpha always named "Freisteller". To use InDesigns "FitBoxToContent" a clipping-path must be temporary choosen.
      Bildschirmfoto 2017-02-03 um 14.01.41.png

       

      As for now, I do these steps by hand…and far too often :-/

       

      1.) Choose
      Type: AlphaChannel
      Alpha: Always named "Freisteller", but not always the first in list.
      InnerShift: -2mm
      Bildschirmfoto 2017-02-03 um 14.18.04.png

       

      2.) Call FitFrame2Content
      Bildschirmfoto 2017-02-03 um 14.03.26.png

       

      3.) Set ClippingPath to None

      Bildschirmfoto 2017-02-03 um 14.18.34.png

        • 1. Re: Actions (like in PS/Illu) in InDesign / functions batch?
          George_Salnik Adobe Community Professional

          InDesign have scripts, but not have actions.

          Sad but true.

           

          You can ask some script-writers to do script that you need (by money or no).

          • 2. Re: Actions (like in PS/Illu) in InDesign / functions batch?
            jane-e Adobe Community Professional

            Method 1:

            Some of this can be done with an Object Style. Perform the steps once. Then select your frame and create a new object style. Edit the Object Style and uncheck anything you don't want, such as fill, stroke, corner options or whatever.

             

            Then Apply the Object Style to the next time you use the frame.

             

            Method 2:

            Put this image into an InDesign library or CC library and pull out the formatted frame.

             

            Post if you need more clarification.

            • 3. Re: Actions (like in PS/Illu) in InDesign / functions batch?
              DBLjan Level 2

              Method 1 is not applicable – there is no option for clipping-path in there. Its the dealbreaker: Only if you apply a clipping-path, the feature Fit2Frame (also the option in the object styles) works. Otherwise there is no change, InDesign not knowing where to allign.

               

              Also I have to say: The image dimensions are different every time. So, its not a picture, neither a given picturebox size thingy.

               

              Heres why:

              I place a file, importing with a alpha-mask. I want to allign/arrange that imagebox, so the content has to be the dimension of the box. But an alphamask is not true or false, so InDesign cant fit that box. Only if theres a simulation of the real alpha by the clippingpath. Using this to fit the box, then disabling the true/false-bossing and using the alphamask again.

              • 4. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                jane-e Adobe Community Professional

                You might ask on the InDesign Scripting forum to see if someone can help you there:

                InDesign Scripting

                • 5. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                  Kasyan Servetsky Level 5

                  Here's a quick & dirty script I wrote for about 5 minutes in CC 2015 on Mac (untested in other versions/on PC):

                  var scriptName = "FitFrame2Content",
                  doc;
                  
                  app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "\"" + scriptName + "\" Script");
                  
                  //===================================== FUNCTIONS ======================================
                  function Main() {
                      var link, image, container, clippingPath,
                      links = doc.links;
                      
                      for (var i = 0; i < links.length; i++) {
                          link = links[i];
                          
                          if (link.linkType == "TIFF" || link.linkType == "Photoshop") {
                              image = link.parent;
                              container = image.parent;
                              clippingPath = image.clippingPath;
                              
                              with (clippingPath) {
                                  clippingType = ClippingPathType.ALPHA_CHANNEL;
                                  appliedPathName = "Freisteller";
                                  insetFrame = -2;
                                  threshold = 25;
                                  tolerance = 2;
                                  includeInsideEdges = false;
                                  invertPath = false;
                                  restrictToFrame= false;
                                  useHighResolutionImage = true;
                              }
                          
                              container.fit(FitOptions.FRAME_TO_CONTENT);
                          }
                      }
                  }
                  //--------------------------------------------------------------------------------------------------------------------------------------------------------
                  function PreCheck() {
                      if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
                      doc = app.activeDocument;
                      if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);
                      if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
                      Main();
                  }
                  //--------------------------------------------------------------------------------------------------------------------------------------------------------
                  function ErrorExit(error, icon) {
                      alert(error, scriptName, icon);
                      exit();
                  }
                  

                   

                  This script works with the current document, but can be easily adjusted to work with my batch processor script.

                   

                  Hope this helps.

                   

                  — Kas

                  • 6. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                    Laubender Adobe Community Professional & MVP

                    DBLjan wrote:

                    … I place a file, importing with a alpha-mask. I want to allign/arrange that imagebox, so the content has to be the dimension of the box. But an alphamask is not true or false, so InDesign cant fit that box. Only if theres a simulation of the real alpha by the clippingpath. Using this to fit the box, then disabling the true/false-bossing and using the alphamask again.

                     

                     

                    Hi Jan,

                    I think it is doable by scripting.


                    But it is only pixel-perfect doable by cross-scripting InDesign with PhotoShop.

                    Doing a clipping path as a helper-element from an Alpha Mask is far from perfect.

                     

                    One would need PhotoShop to calculate the exact dimensions. The rectangle (dims and position) that you get for all drawing pixels of just the image in x/y parallel to the page borders. That does not necessarily mean that one has to open the original placed TIFF or PhotoShop file in PhotoShop. Possibly a high-res rendered frame in grayscale exported as PDF and rendered with PhotoShop would be sufficient. Reading out the pixel dimensions of drawing pixels from PhotoShop together with the offset from the image that has the dimensions of the frame where we started from in InDesign.

                     

                    Regards,
                    Uwe

                    • 7. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                      Kasyan Servetsky Level 5

                      Forgot about the step 3: to turn the clipping path off. I was in a hurry to catch the last metro train. Will fix this tomorrow.

                      I guess adding (after line 31) the following line should turn off the path:

                      clippingPath.clippingType = ClippingPathType.NONE;

                       

                      -- Kas

                      • 8. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                        Laubender Adobe Community Professional & MVP

                        Hi Kas,

                        I think, Jan presented an "idealized" sample.

                         

                        There is are some obstacles, that we have to remember when working with the fit method:
                        InDesign is not good with fitting rotated images inside containers to content. Not at all.

                         

                        So I would use the Alpha Mask with insetFrame value of 0 and convert it to a clipping path.
                        The geometric bounds of that clipping path are the bounds we're after. Plus the additional value Jan wanted for insetFrame.

                         

                        Why? See the following example.


                        The placed image is not cropped. The Alpha Mask is touching the edge of the image.

                        Have a look at the bottom edge of the frame.

                         

                        Before running the script:

                         

                        BeforeRunningScript.png

                         

                        After running the script:

                         

                        AfterRunningScript.png

                         

                        And also:
                        Working with a clipping path calculated from an Alpha Mask is far from pixel perfect.

                         

                        If the image is rotated inside the container frame the result of a fit to contents is a catastrophy:

                         

                        RotatedImageInsideContainer-1.png

                         

                        After running the script:

                         

                        FitFrameToContents-2.png

                         

                        Regards,
                        Uwe

                        1 person found this helpful
                        • 9. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                          rob day Adobe Community Professional & MVP

                          I dont know, why these are features in Photoshop and Illustrator for decades, but not (yet?) in InDesign.

                          I think the reason is the possible variables in InDesign relative to Photoshop are enormous. If you've ever tried using a third party macro utility like QuicKeys to make action like sequences in InDesign they invariably break down. Even with the incredibly robust scripting API where we can catch exceptions, covering all of the variables is still challenging as Uwe's #8 shows.

                          • 10. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                            Kasyan Servetsky Level 5

                            Hi Uwe,

                             

                            I totally agree with you: this approach is far from perfect. However, the OP, if I got him right, wanted simply 'record' the three steps and 'replay' them against all the images in a document (or maybe even in all open documents, or in all documents in a folder). Probably the images in his documents are not scaled and not rotated, etc. so what you described in your post 8 isn't applicable to his particular situation. This is, as I've already mentioned, a quick-and-dirty script and I didn't promise it would work for everyone in all circumstances.

                            Anyway, here's a new -- a little improved version -- added a try-catch block in case something goes wrong: e.g. the "Freisteller" alpha channel is missing.

                            Forgot to mention: the user can Undo-Redo the whole script.

                             

                            var scriptName = "FitFrame2Content",
                            doc;
                            
                            app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "\"" + scriptName + "\" Script");
                            
                            //===================================== FUNCTIONS ======================================
                            function Main() {
                                var link, image, container, clippingPath,
                                links = doc.links;
                                
                                for (var i = 0; i < links.length; i++) {
                                    try {
                                        link = links[i];
                                        
                                        if (link.linkType == "TIFF" || link.linkType == "Photoshop") {
                                            image = link.parent;
                                            container = image.parent;
                                            clippingPath = image.clippingPath;
                                    
                                            with (clippingPath) {
                                                clippingType = ClippingPathType.ALPHA_CHANNEL;
                                                appliedPathName = "Freisteller";
                                                insetFrame = -2;
                                                threshold = 25;
                                                tolerance = 2;
                                                includeInsideEdges = false;
                                                invertPath = false;
                                                restrictToFrame= false;
                                                useHighResolutionImage = true;
                                            }
                                        
                                            container.fit(FitOptions.FRAME_TO_CONTENT);
                                            clippingPath.clippingType = ClippingPathType.NONE;
                                        }
                                    }
                                    catch(err) {
                                        $.writeln(err.message + ", line: " + err.line);
                                    }
                                }
                            }
                            //--------------------------------------------------------------------------------------------------------------------------------------------------------
                            function PreCheck() {
                                if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
                                doc = app.activeDocument;
                                if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);
                                if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
                                Main();
                            }
                            //--------------------------------------------------------------------------------------------------------------------------------------------------------
                            function ErrorExit(error, icon) {
                                alert(error, scriptName, icon);
                                exit();
                            }
                            

                             

                            Regards,
                            Kasyan

                            • 11. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                              DBLjan Level 2

                              Kasyan, i'm, as always, very impressed by your scripting skills and your will to help and share, thank you for that. Also, thanks for chiming in Uwe, Rob and Jane-e.

                               

                              This script is nearly perfect, ill try to alter it to the intent, that it will be executed on current selected picture box.

                               

                              Also, Uwe is damn right when it comes to FF2C and the content is rotated. Every minor or mayor release im baffled how the FF2C-feature could slip again and not being overhauled – and yes, its in the bug/featurerequest forum

                               

                              Hope all your week gets off to a good start!

                              • 12. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                                Kasyan Servetsky Level 5

                                Hi there,

                                 

                                I wish all my clients would always provide me with such a detailed explanation: with screenshots, step-by-step instructions for the script to be written. So I simply couldn't pass your post by.

                                Here's another version which  -- as you asked -- works with the selected image (either with black or white arrow):

                                var scriptName = "FitFrame2Content";
                                app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "\"" + scriptName + "\" Script");
                                //===================================== FUNCTIONS ======================================
                                function Main(image) {
                                    try {
                                        if (image.itemLink.linkType == "TIFF" || image.itemLink.linkType == "Photoshop") {
                                            var container = image.parent,
                                            clippingPath = image.clippingPath;
                                    
                                            with (clippingPath) {
                                                clippingType = ClippingPathType.ALPHA_CHANNEL;
                                                appliedPathName = "Freisteller";
                                                insetFrame = -2;
                                                threshold = 25;
                                                tolerance = 2;
                                                includeInsideEdges = false;
                                                invertPath = false;
                                                restrictToFrame= false;
                                                useHighResolutionImage = true;
                                            }
                                        
                                            container.fit(FitOptions.FRAME_TO_CONTENT);
                                            clippingPath.clippingType = ClippingPathType.NONE;
                                        }
                                    }
                                    catch(err) {
                                        $.writeln(err.message + ", line: " + err.line);
                                    }
                                }
                                //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                function PreCheck() {
                                    if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
                                    if (app.selection.length == 0) ErrorExit("Nothing is selected. Please select an image and try again.", true);
                                    if (app.selection.length > 1) ErrorExit("Please select only one image and try again.", true);
                                
                                    var sel = app.selection[0];
                                    
                                    try {    
                                        if (sel.constructor.name == "Image") {
                                            var image = sel;
                                        }
                                        else if (sel.images.length == 1) {
                                            var image = sel.images[0];
                                        }
                                        else {
                                            ErrorExit("No image in the selection.", true);
                                        }
                                    }
                                    catch(err) {
                                        ErrorExit("Unable to get image from the selection.", true);
                                    }
                                
                                    Main(image);
                                }
                                //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                function ErrorExit(error, icon) {
                                    alert(error, scriptName, icon);
                                    exit();
                                }
                                

                                 

                                — Kas

                                2 people found this helpful
                                • 13. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                                  DBLjan Level 2

                                  Im struggeling with JS again, trying to alter Kas' code, because I encountered images which arent as technical clean as our lookbook told them. The assumption that the desired alpha is named "Freisteller" isn always true.

                                   

                                  I thought, the code, which is awesome for 90% for our images, can be altered by me and my subpar js-skills, but I was wrong:

                                  var alphanames = clippingPath.alphaChannelPathNames;

                                  is working correct, throwing me an array, but…

                                  var alphaIndex = alphanames.indexOf("Freisteller");

                                  will cancel the script somehow.

                                  So im stopped in my early steps, and i dont know how. A little help appriciated!

                                   

                                  While some coders read that – do you guys also have a hard time with the ExtendScript Toolkit CC 2017?
                                  This are my first works with that version, CC 2015 was fine, but CC 2017 is…

                                  …lagging very hard. Every 5-10 sec the app stops for 2 secs. Very annoying.

                                  …is crashing when trying to select "fonts and colors" panel in preferences, to up the font size a bit. Any workaround?

                                  • 14. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                                    Kasyan Servetsky Level 5

                                    While some coders read that – do you guys also have a hard time with the ExtendScript Toolkit CC 2017?
                                    This are my first works with that version, CC 2015 was fine, but CC 2017 is…

                                    …lagging very hard. Every 5-10 sec the app stops for 2 secs. Very annoying.

                                    …is crashing when trying to select "fonts and colors" panel in preferences, to up the font size a bit. Any workaround?

                                    You're on Mac, aren't you? See this thread.

                                    — Kas

                                    • 15. Re: Actions (like in PS/Illu) in InDesign / functions batch?
                                      Laubender Adobe Community Professional & MVP

                                      Hi Jan,

                                      why do you do your work with InDesign CC 2017 ?
                                      Is there a particular feature you are using like in footnotes?

                                       

                                      Still I would not recommend CC 2017 for production work until a bug fix version is out.

                                      One of my customers insists in CC 2017 and I find it crawling slow compared with CS6 on the same machine.

                                       

                                      The method Kasyan is pointing to to make the ESTK fast again ( hm, not slow again ) works like a charm for me:

                                      Re: ID CC 2014 plus ExtendScript (Yosemite) slow to the point of not working...
                                      Thanks to Gregor Fellenz!

                                       

                                      In case someone is coming accross this thread here, I post my comment and screenshot here as well:

                                       

                                      Setting App Nap system wide to false is working great on OSX 10.10.

                                      ExtendScript Toolkit is finally working as expected.

                                       

                                      AppNap-False.png

                                       

                                      Regards,
                                      Uwe