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

Community Beginner ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.3K

Likes

translate

Translate

Translate

Report

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

correct answers 1 Correct Answer

Guide , Jul 31, 2018 Jul 31, 2018
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 Vinnyif (parseFloat(app.version) < 6) {    main();} else {    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Link2ObjectStyle");}function main() {    if (app.do...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

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

Regards,
Uwe

Likes

translate

Translate

Translate

Report

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
Guide ,
Jul 31, 2018 Jul 31, 2018

Copy link to clipboard

Copied

In InDesign, How to apply an Object Style to the frames those has same specific link image? - Graphi...

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.itemLink.name.search(myString) != -1) {

                            myLinks.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

Likes

translate

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 31, 2018 Jul 31, 2018

Copy link to clipboard

Copied

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

Likes

translate

Translate

Translate

Report

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
Guide ,
Jul 31, 2018 Jul 31, 2018

Copy link to clipboard

Copied

Good point, thanks ^^

Likes

translate

Translate

Translate

Report

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 Beginner ,
Jul 31, 2018 Jul 31, 2018

Copy link to clipboard

Copied

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!

Likes

translate

Translate

Translate

Report

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 Beginner ,
Jul 31, 2018 Jul 31, 2018

Copy link to clipboard

Copied

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!

Likes

translate

Translate

Translate

Report

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