24 Replies Latest reply on Aug 12, 2008 4:37 AM by Loic.Aigon

    Graphics to Buttons Script

    Level 1
      Hi,
      I need a script that does the same thing as the sample script "LabelGraphics.jsx" that comes bundled with InDesignCS3
      that instead of labeling all the graphics with the original file name
      creates buttons that link to the original files (kind of a ImageBank).
      Any help is mostly appreciated!
      Cheers
        • 1. Re: Graphics to Buttons Script
          Loic.Aigon Adobe Community Professional
          Here is one script I wrote for you,
          let me know if it's what you are asking for.
          Loic
          http://dl.free.fr/pn2k68INh
          • 3. Re: Graphics to Buttons Script
            Level 1
            Hi Loic,
            Thanks a lot for your efforts I really appreciate it.
            My Feedback:
            -The script creates a new doc with all the images and labels them allright,but no buttons.(to test I exported it to PDF with interactive options checked but no buttons in PDF either)
            -When I run the script inside the ESTK 2 to debug got an error in the first line:undefined is not an object.
            var mydoc = app.documents.add({pageWidth:"210mm", pageheigth:"297mm", name:"image_bank"});
            --------------------------------------------------------------------
            I think it is the closest script for my purposes but not quite what I asked for.
            I want the buttons(or even hyperlinks) to be on the original indd. file.
            like:var mydoc=app.active Document;

            So in short what I want to accomplish is;

            -Get the active document
            -then loop through the graphics
            -sets a button OR hyperlinks
            -sets the URL field to the "Graphic File Name"

            That's all.No dialog is even needed.
            Well it would be cool to have a prefix dialog to add text before the File name(a relative link like /images/ etc. but not rudimentary.

            Without dialog or comment lines I think it would not take more than
            10 lines of code.
            I have just started to learn Javascript(noob) and I have a hard time to get the commands I need from the InDesign Object Model dictionary.
            The info is there I know but I have no idea what to put where.

            Waiting for your reply anxiously.
            Cheers
            • 4. Re: Graphics to Buttons Script
              Level 1
              oops,
              You can forget about the undefined is not an object error,
              I forgot to check InDesign from dropdown menu.

              Nevertheless, the buttons still do not work..

              regards
              • 5. Re: Graphics to Buttons Script
                Loic.Aigon Adobe Community Professional
                Ok thomas,
                I won't probably be able to correct it before monday. But I will as soon as possible.
                In indesign, once you launched the script, do you "see" the buttons in normal mode ? The groups may contain the graphic frame, the label frame and the button.
                Keep in touch.
                Loic
                • 6. Re: Graphics to Buttons Script
                  Level 1
                  Hi Loic,
                  The buttons do not appear in normal mode.
                  The Graphic and the belonging label do not appear to be "grouped",either.
                  Also no PDF creation dialog.
                  The only dialog I get is "Specify Image Folder"
                  and the main dialog box
                  with Information,Options and Labels.
                  Thanks.
                  Thomas
                  • 7. Re: Graphics to Buttons Script
                    Loic.Aigon Adobe Community Professional
                    I am still working on it but I am facing a weird trouble.
                    Keep you in touch
                    • 8. Re: Graphics to Buttons Script
                      Level 1
                      I'll keep my fingers crossed:)
                      Cheers
                      • 9. Re: Graphics to Buttons Script
                        Level 1
                        Hi Loic,
                        could you get it working?
                        Cheers
                        • 10. Re: Graphics to Buttons Script
                          Loic.Aigon Adobe Community Professional
                          Hi sorry for the delay ;-)
                          I have family at home and can't spend as much time I would like on it.
                          I have a matter with the grouping behaviour that I try to fix. The thing is that so far if a link point to a graphic frame that is a part of a group, the script fails. So I have to handle both situations, grouped and ungrouped images.
                          In the worst case I can send you a version that won't group anything so, it will probably work for most cases but it can't be less convenient if you want to move these items later for example.
                          Or I can tell the script to ignore frames that are part of a group. But it can't be satisfying for you.
                          Up to you but if you can't wait for me for a while, I would like to solve this group matter. Or if you are in a hurry I can send you a "unstable" version that will go correctly with ungrouped images but fail with groups.
                          Loic
                          • 11. Re: Graphics to Buttons Script
                            Level 1
                            loic,

                            I guess you could make a lot simpler in just putting a ne button on top of the image on its own layer. Thus you do not need to unscramble any group structures etc. You simply go through the list of links, get the parent of the parent (i.e. the frame) and use its geometric bounds to create a new button.

                            This seems to work in my tests:
                            // buttons_on_images.jsx
                            
                            // © Gerald Singelmann, 08/2008
                            // Zur Erstellung von Bildkatalogen.
                            //
                            // Legt auf jedes Bild eine gleich große, farblose Schaltfläche, die einen Link auf das Bild enthält
                            // So können die Bilder aus Acrobat heraus direkt in Photoshop / Illustrator geöffnet werden
                            //
                            // Gebrauch wie immer auf eigene Gefahr,
                            // wir können nicht garantieren, dass das Script nicht mal unerwartete Ergebnisse erzeugt

                            main();

                            function main() {
                              var aDoc = app.documents[0];
                              var allLinks = aDoc.links;
                              var noSwatch = aDoc.swatches.itemByName("None");
                              try {
                                var bLayer = aDoc.layers.itemByName("Buttons");
                                var t = bLayer.name;
                              } catch (e) {
                                var bLayer = aDoc.layers.add();
                                bLayer.name = "Buttons";
                              }

                              for (var n = 0; n < allLinks.length; n++) {
                                var aLink = allLinks[n];
                                var aFrame = aLink.parent.parent;
                                var aPage = getPage(aFrame);
                                if (aPage != false) {
                                  var aButton = aPage.buttons.add();
                                  with (aButton) {
                                    itemLayer = bLayer;
                                    geometricBounds =aFrame.geometricBounds;
                                    fillColor = noSwatch;
                                    strokeColor = noSwatch;
                                  }
                                  var oBH = aButton.openFileBehaviors.add()
                                  with (oBH) {
                                    behaviorEvent = BehaviorEvents.MOUSE_UP;
                                    enableBehavior = true;
                                    filePath = aLink.filePath;
                                  }
                                }
                              }
                            }

                            function getPage(aThing) {
                              var aClass = aThing.constructor.name;
                              switch (aClass) {
                                case "Page":
                                case "Spread":
                                case "MasterSpread":
                                  return aThing;
                                case "Document":
                                  return false;
                                case "Text":
                                case "InsertionPoint":
                                case "Character":
                                case "Word":
                                case "TextStyleRange":
                                case "Line":
                                case "Paragraph":
                                case "TextColumn":
                                  return getPage(aThing.parentTextFrames[0]);
                                default:
                                  return getPage(aThing.parent);
                              }
                            }
                            • 12. Re: Graphics to Buttons Script
                              Level 1
                              No worries at all Loic,family is most important!
                              I appreciate your time and willingness to help.
                              By the way Gerald; just ran your script on a sample file.
                              and you know what?It works great!
                              Thank you all guys.
                              Great community!
                              Cheers
                              • 13. Re: Graphics to Buttons Script
                                Loic.Aigon Adobe Community Professional
                                Obviously quick and efficient. Well done Gerald. I am a little bit concerned by the grouping theory. It could be helpful for handling the objects in a second time. But Tomas if it is ok for you, it's cool !
                                Anyway, even if you want to redistribute objects, you can come back to a genuine document and relaunch gerald's script.
                                Tomas, do you consider your need as completed or is it anything we could do more ?
                                • 14. Re: Graphics to Buttons Script
                                  Level 1
                                  Dear Loic,
                                  My needs are indeed completed.
                                  The good thing is I can make use of both your and Gerald's script. For example: if I want to use the original PDF Layout, I can go with Gerald's script only.
                                  If I want to produce a PDF with the Graphics only(Catalog mode): I first run your script for layout and use Gerald's script after wards; for the interactivity.Both come in handy!

                                  Ooh by the way I made a small customization on Gerald's code and changed the behavior from "Open File" to "Go To URL" with a relative link string in front so that I can upload the PDF to the web server along with the original graphics to be downloaded.

                                  For noobs like me below is the small customization
                                  -------------------------------------------------------------------
                                  Find in Gerald's code:

                                  var oBH = aButton.openFileBehaviors.add()
                                  with (oBH) {
                                  behaviorEvent = BehaviorEvents.MOUSE_UP;
                                  enableBehavior = true;
                                  filePath = aLink.filePath;

                                  Replace with:

                                  var oBH = aButton.gotoURLBehaviors.add()
                                  with (oBH) {
                                  behaviorEvent = BehaviorEvents.MOUSE_UP;
                                  enableBehavior = true;
                                  url ="Put your URL here"+aLink.name;

                                  -------------------------------------------------------------
                                  Happy weekend to both of you!
                                  Cheers
                                  • 15. Re: Graphics to Buttons Script
                                    Level 1
                                    Hi guys I need your help once more.
                                    How do you make the script apply the buttons to only on an active layer instead of applying globally to the document?
                                    Cheers
                                    Thomas
                                    • 16. Re: Graphics to Buttons Script
                                      Loic.Aigon Adobe Community Professional
                                      Hi Thomas,
                                      Obviously you have to check that the object is on the layer you want the script to have effect on.
                                      so it should be something like :

                                      for (var n = 0; n < allLinks.length; n++) {
                                      var aLink = allLinks[n];
                                      var aFrame = aLink.parent.parent;
                                      var aPage = getPage(aFrame);
                                      if (aPage != false && aPage.itemLayer = app.activeDocument.layers.item("mylayer")) {

                                      I am certain Gerald will correct me if I am wrong :-)
                                      • 17. Re: Graphics to Buttons Script
                                        Level 1
                                        Hi Loic!
                                        Nice to hear from you again.
                                        I get a "Object does not support the property or method 'itemLayer'"
                                        on the line below
                                        if (aPage != false && aPage.itemLayer = app.activeDocument.layers.item("mylayer")) {

                                        any ideas?
                                        thanks in advance!
                                        Cheers
                                        • 18. Re: Graphics to Buttons Script
                                          Loic.Aigon Adobe Community Professional
                                          Hi Thomas,
                                          Maybe it's because it doesn't match with Gerald script's logic.
                                          What is the Indesign version you use ?
                                          • 19. Re: Graphics to Buttons Script
                                            Loic.Aigon Adobe Community Professional
                                            if (aPage != false &&
                                            b aFrame
                                            .itemLayer = app.activeDocument.layers.item("mylayer")) {

                                            try this one. APage refers to a page. aFrame to the object.
                                            It should work now. I hope so.
                                            Loic
                                            • 20. Re: Graphics to Buttons Script
                                              Level 1
                                              Hi Loic,
                                              I'm using CS3.
                                              I have a test document which has one graphic on Layer1 and one graphic on Layer2.
                                              When I run your last suggestion replacing "mylayer" with "Layer1"(The layer I want the script to effect)it results in all the graphics being moved
                                              onto the same layer (Layer1).
                                              So no joy here.
                                              I guess you're right about the logic not matching what I try to accomplish.Bump...
                                              • 21. Re: Graphics to Buttons Script
                                                Loic.Aigon Adobe Community Professional
                                                Hi Thomas,
                                                Ok I am stopping advising you blindly. Let me take the time to fully integrate Gerald script logic. I hope I can give you good news soon.
                                                I tried to warn Gerald that we needed his help, I hope he got the message ;-)
                                                Loic
                                                • 22. Re: Graphics to Buttons Script
                                                  Level 1
                                                  All right mate,
                                                  waiting for your good news!:)
                                                  • 23. Re: Graphics to Buttons Script
                                                    Level 1
                                                    Hi Loic,<br />I think I solved it!:)<br />Below is the customized part of Gerald's script:<br />------------------------------------------------<br />function main() { <br />  var aDoc = app.documents[0]; <br />  var xlayer=aDoc.activeLayer;<br />  var xgraphics=xlayer.allGraphics;<br />  var allLinks = xgraphics.links; <br />  var noSwatch = aDoc.swatches.itemByName("None"); <br />  try { <br />    var bLayer = aDoc.layers.itemByName("Buttons"); <br />    var t = bLayer.name; <br />  } catch (e) { <br />    var bLayer = aDoc.layers.add(); <br />    bLayer.name = "Buttons"; <br />  } <br /><br />  for (var n = 0; n <xgraphics.length; n++) { <br />    var aLink = xgraphics[n].itemLink; <br />    var aFrame = aLink.parent; <br />----------------------------------------------------------<br />Thanks again mate for your support!:)<br />Cheers
                                                    • 24. Re: Graphics to Buttons Script
                                                      Loic.Aigon Adobe Community Professional
                                                      If you got through it with success, I am glad for you :-)
                                                      Loic