6 Replies Latest reply on Jul 31, 2018 10:19 AM by roozye

    Script to apply an Object Style to the frames those has same specific link image?

    roozye Level 1

      Script to select a specific link and an object style to apply to.

      It searches document and applies the style to all frames contents that link.

        • 1. Re: Script to apply an Object Style to the frames those has same specific link image?
          Laubender Adobe Community Professional & MVP

          What did you try so far?
          Show us some code we can comment on.

           

          Regards,
          Uwe

          • 2. Re: Script to apply an Object Style to the frames those has same specific link image?
            vinny38 Level 5

            In InDesign, How to apply an Object Style to the frames those has same specific link image? - Graphic Design Stack Excha…

             

            Something like this maybe?

            (comments from experts are more than welcome)

             

            // [310718] Link2ObjectStyle
            // Apply object style to graphic frames in regard to linked file name
            // written by Vinny
            
            
            if (parseFloat(app.version) < 6) {
                main();
            } else {
                app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Link2ObjectStyle");
            }
            
            
            function main() {
                if (app.documents.length > 0) {
            
            
                    //------------
                    //Variables 
                    var
                        myDoc = app.documents[0],
                        myObjectStyles = myDoc.objectStyles.everyItem(),
                        myLinks = myDoc.allGraphics;
            
            
                    //------------
                    //Dialog box  
                    var myDialog = app.dialogs.add({
                        name: "Apply object style to graphic frames in regard to linked file name",
                        canCancel: true
                    });
                    with(myDialog) {
                        with(dialogColumns.add()) {
                            with(borderPanels.add()) {
                                with(dialogColumns.add()) {
                                    staticTexts.add({
                                        staticLabel: "File name contains:"
                                    });
                                }
                                with(dialogColumns.add()) {
                                    var myTextEditField = textEditboxes.add({});
                                }
                            }
                            with(borderPanels.add()) {
                                with(dialogColumns.add()) {
                                    staticTexts.add({
                                        staticLabel: "Apply object style:"
                                    });
                                }
                                with(dialogColumns.add()) {
                                    var myObjectStylesMenu = dropdowns.add({
                                        stringList: myObjectStyles.name,
                                        selectedIndex: 0
                                    });
                                }
                            }
                        }
            
            
                        if (myDialog.show() == true) {
                            var myString, myObjectStyle, myObjectStylesMenu, fileName, j = 0;
                            myString = myTextEditField.editContents;
                            myObjectStyle = myDoc.objectStyles[myObjectStylesMenu.selectedIndex];
                            myDialog.destroy();
            
            
                            //------------
                            //let's rock
                            if (myString == "") {
                                alert("you didn't enter any string");
                                return null;
                            } else {
            
            
                                for (i = 0; myLinks.length > i; i++) {
                                    if (myLinks[i].itemLink.name.search(myString) != -1) {
                                        myLinks[i].parent.applyObjectStyle(myObjectStyle);
                                        j++;
                                    }
                                }
            
            
                            //------------
                            //end
                                if (j == 0) {
                                    alert("String could not be found\nScript ends");
                                } else {
                                    alert(j + " objects found.\nYou're done");
                                }
                            }
            
            
                        } else {
                            myDialog.destroy()
                        }
                    }
            
            
                } else {
                    alert("Open a document");
                    return null
                }
            }
            

             

            cool.gif

            • 3. Re: Script to apply an Object Style to the frames those has same specific link image?
              Laubender Adobe Community Professional & MVP

              Hi Vinny,

              if you want also object styles in style groups loop the allObjectStyles array of the document to gather your string list.

               

              Regards,
              Uwe

              1 person found this helpful
              • 5. Re: Script to apply an Object Style to the frames those has same specific link image?
                roozye Level 1

                I don't know coding and start it here to find some help with that matter.

                Vinny tried some codes, I run it asap and reply soon.

                Don't know if I started this disscusion in right forum! sorry!

                • 6. Re: Script to apply an Object Style to the frames those has same specific link image?
                  roozye Level 1

                  Not tried it yet, but gif shows even more than what I had in mind!!

                  It can even find certain extention of file or any kind of text that contains in the file name! looks amazing! Now time to talk about those Strawberries and potatos!! Or even grapefruits and ... bananas... maybe!