Skip to main content
Inspiring
December 28, 2011
Question

Issue with setting ratings and labels

  • December 28, 2011
  • 1 reply
  • 916 views

Greetings all. I am having an issue with setting ratings AND labels on image files at the same time. If the script sets the label first then the rating, the label doesn't show in Bridge. If the script sets the rating first then the label, the rating doesn't show in Bridge.

Is there a workaround for this? Here is my script function for doing this. file=filename minus extension. Rating is a number for the desired rating. lab is a number for the level of Label I wish to set. Everything works great except that I can't set both Rating and Label with the script as shown. In this instance, only the Ratings will show up in Bridge after running the script. If I move the x.label=Label line under the x.rating=Rating line, then the ratings only show for those images with no label (lab=0). Any image that gets a label receives no rating.

If you're going to test this, you may want to comment out the Collections part. That's the part within the "switch(Number(Rating))" block.

function setRating(file,Rating,lab) {

    try{

        cr=File(file+"CR2");

        psd=File(file+"psd");

        jpg=File(file+"jpg");

        tif=File(file+"tif");

       

        switch(lab) {

            case 0: Label = ""; break;

            case 1: Label = "Select"; break;

            case 2: Label = "Second"; break;

            case 3: Label = "Approved"; break;

        }

       

        if (cr.created) {

            var c=new Thumbnail(cr);

            c.label=Label;

            c.rating=Rating;

            if (psd.created) {

                p=new Thumbnail(psd);

                p.label=Label;

                p.rating=Rating;

                if (jpg.created) {

                    var j=new Thumbnail(jpg);

                    j.label=Label;

                    j.rating=Rating;

                    Rating=0;

                }

                else addFile=psd;

            }

            else addFile=cr;

        }

        switch(Number(Rating)){

            case 0 : break; /* No Rating */

            case 1 : if(!app.isCollectionMember(OneStar,new Thumbnail(addFile))) app.addCollectionMember(OneStar,new Thumbnail(addFile)); break;

            case 2 : if(!app.isCollectionMember(TwoStars,new Thumbnail(addFile))) app.addCollectionMember(TwoStars,new Thumbnail(addFile)); break;

            case 3 : if(!app.isCollectionMember(ThreeStars,new Thumbnail(addFile))) app.addCollectionMember(ThreeStars,new Thumbnail(addFile)); break;

            case 4 : if(!app.isCollectionMember(FourStars,new Thumbnail(addFile))) app.addCollectionMember(FourStars,new Thumbnail(addFile)); break;

            case 5 : if(!app.isCollectionMember(FiveStars,new Thumbnail(addFile))) app.addCollectionMember(FiveStars,new Thumbnail(addFile)); break;

            default : break;

        }

    }catch(e){

          alert(e);

          return -1;

     }

}

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
December 28, 2011

Afew errors to start with, you were not creating a proper file as there wasn't a fullstop in the filename.

If a CR2 file didn't exist no other file was looked for, you were using "created" and should have been "exists"

This now labels and rates....

setRating("/C/Test Area/NEF/z",2,1);

function setRating(file,Rating,lab) {
    try{
        cr=File(file+".CR2");
        psd=File(file+".psd");
        jpg=File(file+".jpg");
        tif=File(file+".tif");
       
        switch(Number(lab)) {
            case 0: Label = ""; break;
            case 1: Label = "Select"; break;
            case 2: Label = "Second"; break;
            case 3: Label = "Approved"; break;
        }

        if (cr.exists) {
            var c=new Thumbnail(cr);
            c.label=Label;
            c.rating=Rating;
            }
            if (psd.exists) {
                p=new Thumbnail(psd);
                p.label=Label;
                p.rating=Rating;
                }
                if (jpg.exists) {
                    var j=new Thumbnail(jpg);
                    j.label=Label;
                    j.rating=Rating;
                    Rating=0;
                }
/*
        switch(Number(Rating)){
            case 0 : break;
            case 1 : if(!app.isCollectionMember(OneStar,new Thumbnail(addFile))) app.addCollectionMember(OneStar,new Thumbnail(addFile)); break;
            case 2 : if(!app.isCollectionMember(TwoStars,new Thumbnail(addFile))) app.addCollectionMember(TwoStars,new Thumbnail(addFile)); break;
            case 3 : if(!app.isCollectionMember(ThreeStars,new Thumbnail(addFile))) app.addCollectionMember(ThreeStars,new Thumbnail(addFile)); break;
            case 4 : if(!app.isCollectionMember(FourStars,new Thumbnail(addFile))) app.addCollectionMember(FourStars,new Thumbnail(addFile)); break;
            case 5 : if(!app.isCollectionMember(FiveStars,new Thumbnail(addFile))) app.addCollectionMember(FiveStars,new Thumbnail(addFile)); break;
            default : break;
        }
*/
    }catch(e){
          alert(e);
          return -1;
     }
}

jugenjuryAuthor
Inspiring
December 29, 2011

Can you explain what you mean by a fullstop in the filename? If you're talking about the . before the extension, that actually gets passed into the function within the "file" variable from another part of the script.

The way my workflow is set up, if there is no CR2 file, there can not be a psd file and if there is no psd file, there can not be a jpg file. That all ties into the part where it adds them to the collections (images that are not yet finished). If a jpg exists, the image is finished so it shouldn't be added. If no jpg exists but a psd does, I want the psd added to the collection and not the RAW (so I don't inadvertently start over). Otherwise add the RAW.

I always thought file.created could be used to check if a file exists since it returns either a date or null. It's been working so far, but I suppose exists would be more appropriate from a coding perspective.

I put your function into my script and get the same results. It will set either a rating or a label but not both on the same thumbnail.