9 Replies Latest reply on Aug 21, 2008 9:21 PM by (Paul_Norwood)

    Star Ratings -- From data source

      Hi,

      I have imported a data source to my page and it includes a number which I'd like to convert to stars (graphics). Is there a simple script that I can use to take the number being imported and convert it to a graphic? If the rating is a 2 I'd like to have two stars, etc ...

      Thanks!
        • 1. Re: Star Ratings -- From data source
          Peter Kahrel Adobe Community Professional & MVP
          CS2? CS3? Where can the number be found? At the beginning of each paragraph? At the end? Is it the only number in the paragraph or line?

          Questions, questions...

          Peter
          • 2. Re: Star Ratings -- From data source
            Level 1
            I am using CS3

            I am doing a data merge and the number is from a field in the table ... not sure if that helps at all ...

            --Paul
            • 3. Re: Star Ratings -- From data source
              Peter Kahrel Adobe Community Professional & MVP
              >the number is from a field in the table

              Which field is that? I guess you mean "cell". So you have a table, and in each row there is a cell with a number in it, and that number needs to be replaced with some stars. Which cell is the number in? The first one?

              Peter
              • 4. Re: Star Ratings -- From data source
                Level 1
                The star rating cell is the fourth one
                • 5. Re: Star Ratings -- From data source
                  Peter Kahrel Adobe Community Professional & MVP
                  Here is a basic script (in the sense that it doesn't do much error checking). Place the cursor in the table you want to process and run the it.

                  Peter

                  #target indesign
                  

                  // Exit if nothing is selected or when the cursor is not in a table
                  if (app.selection.length == 0 ||
                        app.selection[0].parent.parent.constructor.name != 'Table')
                     exit();

                  myCells = app.selection[0].parent.parent.columns[3].cells;
                  for (i = 0; i < myCells.length; i++)
                     {
                     stars = "";
                     rating = myCells[i].contents;
                     for (j = 0; j < rating; j++)
                        stars += '*';
                     myCells[i].contents = stars
                     }
                  • 6. Re: Star Ratings -- From data source
                    Level 1
                    Thanks ...

                    Not sure this will do what I want though. I am performing a data merge and one of the fields in the merge is <<biz_stars>> and during the merge (if possible) I'd like the numeric value replaced with a graphic. For example if the biz_stars = 2 I'd like an image with 2 stars replacing the number and so on ...

                    --Paul
                    • 7. Re: Star Ratings -- From data source
                      Peter Kahrel Adobe Community Professional & MVP
                      Maybe you should have been more explicit in your first query. I don't think it's possible to insert graphics during the merge, but I never use merge so I don't know about that. You probably have to do it after the merge -- but that doesn't make much difference, does it?

                      Inserting the graphics makes the script more complicated. Maybe you should think of hiring someone to write it for you.

                      Peter
                      • 8. Re: Star Ratings -- From data source
                        Level 1
                        You could probably go 3 ways. Run a script after the merge, this would be the best.
                        For each page, get the number/integer of the star rating from the text box. Then have the script draw X number of image frames on the page where ever the rating needs to be, like 3 or 4 small square boxes. You'd have to manually determine the placement of box 1, box 2 etc. Then place a star graphic in each box.
                        Or you could also have the stars drawn as a polygon shape directly in InDesign, drawn as many times as needed.
                        Or draw just one box, long rectangle, and then have 5 images of star ratings, 1 star, 2 star etc. Based on the number, place the file name that begins with that number (ie "1-star.jpg").
                        • 9. Re: Star Ratings -- From data source
                          Level 1
                          Thanks,

                          I actually solved this by having the query for the data merge convert the star rating to characters (e.g. if the rating was a 2 the query printed HH) and then I used a font called "SORTS" which is similar to wingdings. H happens to be a star shape in that font. This solution worked perfectly without any scripting in InDesign, just a little scripting in Access which seems easier to code in.

                          --Paul