5 Replies Latest reply on Jun 2, 2015 2:16 AM by DBLjan

    Image replacement

    HEMU DESAI

      Hi,

       

      Is there a script available in InDesign for replacing Low resolution images with High resolution.

      Both image have same name, only folders are different.

       

      Kind of a OPI function.

       

      Hemanshu

        • 1. Re: Image replacement
          Sajeev Sridharan Level 4

          Hi,

           

          In the Links Panel there's a drop down menu in the top right, choose Relink to Folder and it should relink all the files in one step.


          If you still need script there are lots of code available in the forum, google it and change as per your requirement.

          • 2. Re: Image replacement
            HEMU DESAI Level 1

            Hi,

             

            This I know. But its manual. I am looking at Automation. Run it like batch or action file.

            • 4. Re: Image replacement
              HEMU DESAI Level 1

              Hi,

               

              This is good but still has manual intervention.

              I am looking at thing where I say the folder name from where images are to be taken and replaced in the file.

              Please note that the image file name are same.

               

              Hemanshu

              • 5. Re: Image replacement
                DBLjan Level 2
                set ProgrammName to "A Link from the Past"
                set myLinks to {}
                set errormsg to ""
                set Proz to "100%"
                
                tell application "Adobe InDesign CS5.5"
                    activate
                    if (count documents) = 0 then set errormsg to "Please open a document."
                    try
                        tell active document
                            set AllLinks to (every link whose status is link missing)
                        end tell
                        if (count AllLinks) = 0 then set errormsg to "No broken links found."
                    end try
                   
                    if errormsg is not "" then
                        display dialog "" & errormsg buttons {"Damn!"} default button 1 with icon 0
                    else
                        tell active document
                            set AllLinks to (every link whose status is link missing)
                            my myProgressBarCreate(ProgrammName, "Working links…", length of AllLinks)
                           
                            repeat with k from 1 to (length of AllLinks)
                                set MyItem to item k of AllLinks
                               
                                set OldPath to file path of MyItem as string
                                set OldPath to POSIX path of OldPath
                                set fName to name of MyItem as string
                                set NewPath to OldPath
                               
                                -- NewPath is e.g. "/Volumes/srvmar101_01/DBL DE/folder"
                                -- replaceString looks for e.g. "/srvmar101_01/" in string NewPath and replaces if found with "/srv_new/"
                                -- then, if oldpath ≠ newpath InD tries to relink
                               
                                set NewPath to "" & my replaceString(NewPath, "/SRV_OLD/ThisFolder", "SRV_NEW/NewFolderScructure/ThatFolder")
                                set NewPath to "" & my replaceString(NewPath, "/SRV_OLD/", "SRV_NEW/NewFolderScructure/")
                               
                                try
                                    if OldPath ≠ NewPath then
                                        my ZoomSelection(MyItem)
                                        relink MyItem to POSIX file NewPath
                                    end if
                                end try
                               
                                -- This is the brogressbar text and percent
                                set whatsleft to (((length of AllLinks) + 1) - k)
                                my myProgressBarStatustext("(" & whatsleft & ") – " & fName)
                                set tempzent to round ((((100 / (length of AllLinks))) * k)) as real
                                my myProgressBarIncrement(tempzent & "%")
                               
                            end repeat
                            update every link
                            my myProgressBarClose()
                        end tell
                    end if
                end tell
                
                tell application "Finder"
                    try
                        my myProgressBarClose()
                    on error the error_message number the error_number
                        display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
                    end try
                end tell
                
                on ZoomSelection(vari)
                    tell application "Adobe InDesign CS5.5"
                        set selection to nothing
                        select parent of vari
                        set ZoomSelectionAction to menu action id 118790
                        invoke ZoomSelectionAction
                    end tell
                end ZoomSelection
                
                on myProgressBarCreate(pbBarName, firstAction, pbMax)
                   
                    set pbJS to "#targetengine 'pbar' 
                    var ProgressBar = function(/*str*/title) 
                    { 
                        var w = new Window('palette', ' '+title, {x:0, y:0, width:360, height:60}), 
                              pb = w.add('progressbar', {x:10, y:12, width:300, height:12}, 0, 100),
                        pt = w.add('statictext', {x:320, y:10, width:40, height:20}, ''),
                              st = w.add('statictext', {x:10, y:36, width:360, height:20}, ''); 
                        st.justify = 'left';        w.center(); 
                        this.reset = function(msg,maxValue) 
                              { 
                              st.text = msg; 
                              pb.value = 0; 
                              pb.maxvalue = maxValue||0; 
                              pb.visible = !!maxValue; 
                              w.show(); 
                              }; 
                        this.statustext = function(msg) 
                              { 
                              st.text = msg; 
                              w.show(); 
                              };
                        this.prozent = function(msg) 
                              { 
                              pt.text = msg; 
                              w.show(); 
                              };                   
                         
                        this.hit = function() {++pb.value;}; 
                        this.hide = function() {w.hide();}; 
                        this.close = function() {w.close();}; 
                    }; 
                     
                     
                    pBar = new ProgressBar('" & pbBarName & "'); 
                    pBar.reset('" & firstAction & "', " & pbMax & ");"
                    tell application "Adobe InDesign CS5.5"
                        activate
                        do script pbJS language javascript
                    end tell
                end myProgressBarCreate
                
                
                on myProgressBarStatustext(newText)
                    set pbJS to "#targetengine 'pbar' 
                    pBar.statustext('" & newText & "');"
                    tell application "Adobe InDesign CS5.5" to do script pbJS language javascript
                end myProgressBarStatustext
                
                
                on myProgressBarIncrement(prozent)
                    set pbJS to "#targetengine 'pbar' 
                      pBar.hit()"
                    tell application "Adobe InDesign CS5.5" to do script pbJS language javascript
                    set pbJS to "#targetengine 'pbar' 
                    pBar.prozent('" & prozent & "');"
                    tell application "Adobe InDesign CS5.5" to do script pbJS language javascript
                end myProgressBarIncrement
                
                
                on myProgressBarReset(newAction, newMax)
                    set pbJS to "#targetengine 'pbar' 
                      pBar.reset('" & newAction & "', " & newMax & ");"
                    tell application "Adobe InDesign CS5.5" to do script pbJS language javascript
                end myProgressBarReset
                
                
                on myProgressBarClose()
                    set pbJS to "#targetengine 'pbar' 
                      pBar.close();"
                    tell application "Adobe InDesign CS5.5" to do script pbJS language javascript
                end myProgressBarClose
                
                on replaceString(theText, oldString, newString)
                    local ASTID, theText, oldString, newString, lst
                    set ASTID to AppleScript's text item delimiters
                    try
                        considering case
                            set AppleScript's text item delimiters to oldString
                            set lst to every text item of theText
                            set AppleScript's text item delimiters to newString
                            set theText to lst as string
                        end considering
                        set AppleScript's text item delimiters to ASTID
                        return theText
                    on error eMsg number eNum
                        set AppleScript's text item delimiters to ASTID
                        error "Can't replaceString: " & eMsg number eNum
                    end try
                end replaceString
                

                 

                Maybe this can help you: Cyles thru all broken links, looks for strings to change and relinks.

                With

                set NewPath to "" & my replaceString(NewPath, "/SRV_OLD/ThisFolder/", "/SRV_NEW/NewFolderScructure/ThatFolder/")

                you can set various strings/folders to find and relink to another location.