12 Replies Latest reply on Apr 29, 2009 9:56 AM by ioanna1

    link rows and photos???

    ioanna1

      Couple of tasks

       

      Hello

       

      I am using Indesign CS3 and I am trying to learn JS in order to complete some tasks.

       

      I’ll put this in an example so as to make sence

       

      I want to place 3 pictures with their labels (name of the jpg file). I know how to do that and how to format the labels in the style, color and size I need.

       

      For example the texts in the labels are X1, X2, X3,.

       

      I bring a table from an excel file with 3 rows and 2 columns.

       

      -The text on the right column is the same with the text on the Labels (ex: row 1, column1: X1, row 2, column1: X2, row 3, column1: X3)

      -The text on the left column is the description of X1-X2-X3 (for example, “row1, column1: X1 // row1, column2: pencil, B4 “)

       

      I need

      1. To say to indesign to find the same texts from the labels and the rows

      (in the example : to find X1 in the labels and X1 in the rows.)

       

      2:  To break apart , table’s rows

       

      3. To replace each label with the corresponding rows

      (in the example to replace label X1 with “row1, column1: X1 // row1, column2: pencil, B4 “)

       

      Or perhaps, to place each row in the (example) top left of the corresponding picture.

       

      There is a sample script in indesign that helps find the same objects but is it possible to specify it in particular texts or to specify it in texts (inside tables) and filenames??

       

       

      Thank you in advance…

       

        • 1. Re: link rows and photos???
          Dave Saunders Level 4

          You're mixing up your terminology and inventing some on the fly making it difficult to follow what you're trying to do.

           

          The values of the label are in a column, not a row. So, you need to find a text in a column. Having found it you then need to work-out which row it is in.

           

          But then it gets a bit hazy. You talk of replacing a label with a row. I suspect that what you want to do is replace the contents of a paragraph (the original "label") with the contents of the first cell of the row.

           

          Is that right? Half the time, just getting the terminology straight leads you to the solution.

           

          "label" is a very poor choice of words because a label is a particular property of page items. I suspect that your "label" is a caption paragraph.

           

          Dave

          1 person found this helpful
          • 2. Re: link rows and photos???
            ioanna1 Level 1

             

             

            Thank you for your answer I think this might be extremely helpful

            and if I have corectly understood you are probably right

             

            I am really sorry about the terminology and the confusion

            It’s a bit confusing for me as I have just started trying to understand scripts in indesign.

             

            I named labels (as I have seen it before in another topic) the text that is placed on the images (name of the file , type etc…)

            (for example it’s almost the same thing with Bridge tool: create indesign contact sheet , but I prefer to use a scipt in indesign as I have managed to manipulate, colour, type and size )

             

            If the content of what I called “label” is called “caption paragraph” (or just paragraph???) then

            I need to replace the contents of the first paragraph (the original "label") with the contents of the first cell of the row.

             

            So I do the same with the rest of the paragraphs (labels)? I replace the second paragraph ith the contents of the first cell of the second row etc???

             

            I am sure I’ll find this in the book about indesign script writing - but if there is no harm in asking - do I need to specify texts as caption paragraphs?

             

             

            • 3. Re: link rows and photos???
              Dave Saunders Level 4

              Part of the problem with talking about this stuff is that inevitably we create terminology as we go along. And I did just that when I used "caption paragraph".

               

              You are right that as far as a script is concerned that is just a paragraph. It's a particular one in that it drives what we do with the table. Let's assume that you have a paragraph style called "Caption" that you use for those paragraphs and for no other purpose in the document.

               

              Let's also assume that your table is in a text frame somewhere in the document that you have labeled (using the Script Label panel) "Real Captions".

               

              Now we have enough information to write the script. It needs to do the following:

               

              1. Search the document for every instance of a paragraph in the paragraph style "Caption".

               

              2. For every found paragraph, grab the contents and use that to search column[1] of the table.

               

              3. If there is a hit, duplicate the contents of cell 0 of the row to the original paragraph.

               

              If there isn't a hit or if there is more than one hit, you have to decide what to do.

               

              Here's a JavaScript that does this stuff:

               

              var myDoc = app.documents[0];
              var myPstyle = myDoc.paragraphStyles.item("Caption");
              var myTable = myDoc.textFrames.item("Real Captions").parentStory.tables[0];
              setupFindText();
              app.findTextPreferences.appliedParagraphStyle = myPstyle;
              var myFinds = myDoc.findText();
              for (var j = myFinds.length - 1; j >= 0; j--) {
                  var captionPlaceHolder = myFinds[j].contents;
                  setupFindText(captionPlaceHolder);
                  var myHits = myTable.columns[1].findText();
                  if (myHits.length === 0) { continue } // didn't find placeholder; move on
                  // if there's more than one hit, we'll take the first one
                  var myCellName = myHits[0].parent.name;
                  var cellParts = myCellName.split(":");
                  var captionCell = myTable.cells.item("0:" + cellParts[1]);
                  var myFinds[j].contents = captionCell.texts[0].contents;
              }

               

              function setupFindText(find, change, wholeWd, caseSense, foots,
                                      hidLayers, lockedLayers, lockedStories, masters) {
                  app.findTextPreferences = null;
                  app.changeTextPreferences = null;
                  try { app.findTextPreferences.findWhat = find } catch(e) {};
                  try {app.changeTextPreferences.changeTo = change } catch(e) {};
                  app.findChangeTextOptions.properties = {
                      caseSensitive:(caseSense == null ? false : caseSense),
                      wholeWord:(wholeWd == null ? false : wholeWd),
                      includeFootnotes:(foots == null ? false : foots),
                      includeHiddenLayers:(hidLayers == null ? false : hidLayers),
                      includeLockedLayersForFind:(lockedLayers == null ? false : lockedLayers),
                      includeLockedStoriesForFind:(lockedStories == null ? false : lockedStories),
                      includeMasterPages:(masters == null ? false : masters)
                  }
              } // end setupFindText

               

              I just banged this out off the top of my head and I've not tested it. It might not do exactly what you want, but I imagine that it is close and should get you on your way.

               

              Dave

              1 person found this helpful
              • 4. Re: link rows and photos???
                ioanna1 Level 1

                thanx again

                 

                I really appreciate your time and you hepl..

                 

                It brings me an error Number 25, Error string: expected: ;  (in line 16),

                however I think if I go back to manual I'll find how to correct it..

                • 5. Re: link rows and photos???
                  Dave Saunders Level 4

                  Oops. That's a mistake I make over and over.

                   

                  The 'var' should not be there on the front of that line.

                   

                  Dave

                  • 6. Re: link rows and photos???
                    ioanna1 Level 1

                    ehm..

                     

                    now it brings me the error in line 3 // object is invalid

                     

                    I tried some other names instead of caption but it turned out that wasnt the problem..

                     

                    PS. I think after all this I ought to pay you some money for this script, because I'll be using it alot in my work.

                     

                    if there is a safe way of payment please think about it and let me know because I start feeling really bad about wasting your time in beginers details.

                     

                     

                    --- Στις Τρίτ., 28/04/09, ο/η Dave Saunders <forums@adobe.com> έγραψε:

                     

                     

                    Από: Dave Saunders <forums@adobe.com>

                    Θέμα: link rows and photos???

                    Προς: "ioanna antoniadi" <i_antoniade@yahoo.gr>

                    Ημερομηνία: Τρίτη, 28 Απρίλιος 2009, 17:08

                     

                     

                    Oops. That's a mistake I make over and over.

                     

                    The 'var' should not be there on the front of that line.

                     

                    Dave

                    • 7. Re: link rows and photos???
                      Dave Saunders Level 4

                      You can use either Kagi or Paypal, but there is no obligation. I'm happy to help out someone who is attempting to write their own script.

                       

                      The thing about the script as it stands is that it makes assumptions about the way your document needs to be setup up.

                       

                      On line two, I expect there to be a paragraph style named "Caption" -- if you've used a different name for your style, then edit the script accordingly.

                       

                      On line three (which flows to line four in the forum), I'm looking for the table. You gave no clue where it was so I assumed it would be in a text frame that had been labeled "Real Captions" -- you label a page item by using the Script Label panel. Again, if you prefer to use a different name, edit the script.

                       

                      Perhaps you have some other way of finding the table. It must be contained in a paragraph so if that paragraph has a unique style, it could be found that way. Or, perhaps the text inside the table uses a style not used anywhere else, in which case it can be found that way.

                       

                      Half the battle with writing scripts has to do with setup and workflow rather than the mere coding of the script. As much as possible, make the life of the scripter easy by a well-thought-out setup.

                       

                      Dave

                      • 8. Re: link rows and photos???
                        ioanna1 Level 1

                        Thank you

                        again for the explanation. That’s what I did but it seems I have messed up the

                        names and it didn't work. However I'll check it out and I am sure I'll find

                        what I am doing wrong.

                         

                         

                         

                        It will

                        definitely make me feel better because you didnt just help me write the

                        script.. You actually wrote it and help me understand a lot of details I was

                        missing. Which means you saved me about 3 months of trying to write while

                        learning and trying yo apply this thing in my job...

                         

                         

                         

                         It might take me approximately a week to arrange this thing through

                        paypal, because I don’t have an account so I'll have to use an account from a

                        friend (or to open an account)

                         

                        Would you like to give me the required details of you account on paypal

                         and also your fee for this type of  service?

                         

                         

                         

                         

                         

                         

                         

                        --- Στις Τρίτ., 28/04/09, ο/η Dave Saunders <forums@adobe.com> έγραψε:

                         

                        Από: Dave Saunders <forums@adobe.com>

                        Θέμα: link rows and photos???

                        Προς: "ioanna antoniadi" <i_antoniade@yahoo.gr>

                        Ημερομηνία: Τρίτη, 28 Απρίλιος 2009, 18:01

                         

                        You can use either Kagi or Paypal, but there is no obligation. I'm happy to help out someone who is attempting to write their own script.

                         

                        The thing about the script as it stands is that it makes assumptions about the way your document needs to be setup up.

                         

                        On line two, I expect there to be a paragraph style named "Caption" -- if you've used a different name for your style, then edit the script accordingly.

                         

                        On line three (which flows to line four in the forum), I'm looking for the table. You gave no clue where it was so I assumed it would be in a text frame that had been labeled "Real Captions" -- you label a page item by using the Script Label panel. Again, if you prefer to use a different name, edit the script.

                         

                        Perhaps you have some other way of finding the table. It must be contained in a paragraph so if that paragraph has a unique style, it could be found that way. Or, perhaps the text inside the table uses a style not used anywhere else, in which case it can be found that way.

                         

                        Half the battle with writing scripts has to do with setup and workflow rather than the mere coding of the script. As much as possible, make the life of the scripter easy by a well-thought-out setup.

                         

                        Dave

                        • 9. Re: link rows and photos???
                          Dave Saunders Level 4

                          One very important thing about JavaScript is that it is case dependent. If you have a style named "caption" then the script will give the error because it is looking for "Caption". Also, this script ignores the possibility of grouped styles. If you have "Caption" in a paragraph style group the script (as written) won't work.

                           

                          Visit this page for info about my Kagi and Paypal info: http://tinyurl.com/dl9l7k

                           

                          Dave

                          • 10. Re: link rows and photos???
                            ioanna1 Level 1

                            I

                            have followed the instructions and managed to make it work through line 3 and 4

                            by naming the table with a random word.

                             

                             But now it gives me another error in line 5

                             

                            "

                            invalid value for set property 'appliedparagraphstyle'. Expected String,

                            ParagraphStyle or NothingEnum enumerator, but received nothing//

                             

                             

                             

                             

                             

                            I

                            thought that the problem might have been that I didnt give a paragraph style

                            but the error remained.Perhaps this is an error that I get to understand once I have complited the reading in adobes documents about scipting?

                             

                             

                            I

                            also tried to erase this line (just to see what happens) and gave an error that

                            the object contains no text for find/change

                            PS.I have seen that I can pay with credit card so by the end of  tuesday I will have manage to work this out.

                             

                             

                             

                             

                             

                             

                             

                             

                             

                            --- Στις Τετ., 29/04/09, ο/η Dave Saunders <forums@adobe.com> έγραψε:

                             

                            Από: Dave Saunders <forums@adobe.com>

                            Θέμα: link rows and photos???

                            Προς: "ioanna antoniadi" <i_antoniade@yahoo.gr>

                            Ημερομηνία: Τετάρτη, 29 Απρίλιος 2009, 14:39

                             

                            One very important thing about JavaScript is that it is case dependent. If you have a style named "caption" then the script will give the error because it is looking for "Caption". Also, this script ignores the possibility of grouped styles. If you have "Caption" in a paragraph style group the script (as written) won't work.

                             

                            Visit this page for info about my Kagi and Paypal info: http://tinyurl.com/dl9l7k

                             

                            Dave

                            • 11. Re: link rows and photos???
                              Dave Saunders Level 4

                              The error you're getting on line 5 means that your document doesn't have a paragraph style named "Caption".

                               

                              Dave

                              • 12. Re: link rows and photos???
                                ioanna1 Level 1

                                ok.. I'll go keep reading and I am sure I 'l eventually clear my mess up...

                                 

                                thank you again for you time and all you help . I deeply appreciate it.