Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Star Ratings -- From data source

New Here ,
Aug 20, 2008 Aug 20, 2008
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!
TOPICS
Scripting
824
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2008 Aug 20, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2008 Aug 20, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2008 Aug 20, 2008
>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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2008 Aug 20, 2008
The star rating cell is the fourth one
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2008 Aug 20, 2008
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.contents;
for (j = 0; j < rating; j++)
stars += '*';
myCells.contents = stars
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2008 Aug 20, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2008 Aug 21, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 21, 2008 Aug 21, 2008
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").
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 21, 2008 Aug 21, 2008
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines