7 Replies Latest reply on Jul 31, 2018 12:00 AM by wallaceh3639989

    Remove All Missing Links with frames

    HarveyLiu Level 1

      How can I make a script to remove all missing links with frames In indesign?

       

      var doc = app.activeDocument;
      var links = doc.links;

      for (var i = links.length-1; i >= 0; i--) {
      if (links[i].status == LinkStatus.LINK_MISSING) {
        try {
         links[i].parent.remove();
                   var image = link.parent;
                var frame = image.parent;
                frame.remove();
                counter++;

        }
        catch (err) {
         $.writeln(i + " - " + err);
        }
      }
      }

       

      I try this script, but still remain a frame, what's wrong with that?

        • 1. Re: Remove All Missing Links with frames
          Kasyan Servetsky Level 5

          This works for me:

          var link, image, frame,
          doc = app.activeDocument,
          links = doc.links,
          counter = 0;
          
          for (var i = links.length-1; i >= 0; i--) {
              if (links[i].status == LinkStatus.LINK_MISSING) {
                  try {
                      link = links[i];
                      image = link.parent;
                      frame = image.parent;
                      frame.remove();
                      counter++;
                  }
                  catch (err) {
                      $.writeln(i + " - " + err);
                  }
              }
          }
          
          • 2. Re: Remove All Missing Links with frames
            Laubender Adobe Community Professional & MVP

            @Harvey – in priciple nothing's wrong with that.

             

            But you need only to remove the parent.parent of the found link.

             

            You could also resolve the object that is behind parent.parent to make sure it will work:

             

            var myContainerToRemove = links[i].parent.parent.getElements()[0];
            myContainerToRemove.remove();
            

             

            No container, no image, no link ;-)

             

            Of course that will leave a container frame behind, if the container of the graphic is itself nested into another object.

            This could be a Texts object (together with a text frame) or a SplineObject like a Rectangle, Oval, Polygon, a Button as well as a State inside an MSO…

             

            A remnant could also be a Group object containing only one page item…
            Depends on how the page items are used and the layout is constructed.

             

            Uwe

            • 3. Re: Remove All Missing Links with frames
              wallaceh3639989 Level 1

              Is it possible instead of deleting all frames with missing links to leave them at the document but change the graphic style?

              • 4. Re: Remove All Missing Links with frames
                Laubender Adobe Community Professional & MVP

                wallaceh3639989  wrote

                 

                Is it possible instead of deleting all frames with missing links to leave them at the document but change the graphic style?

                Of course. Since you have access to the parent.parent of the missing link you just would assign an object style if links[i].status is e.g. LinkStatus.LINK_MISSING.

                 

                Regards,
                Uwe

                • 5. Re: Remove All Missing Links with frames
                  wallaceh3639989 Level 1

                  Good to know, but unfortunately I'm just a simple graphic designer, I put my question here: Change the graphic style to all frames with missing links

                  • 6. Re: Remove All Missing Links with frames
                    Laubender Adobe Community Professional & MVP

                    Don't give up so soon.

                     

                    See into Kasyan's code. Inspect it.

                     

                    The most important questions:

                    1. What line would you delete or comment out so that the found frame will not be removed?

                    2. What variable would you apply the object style to?

                     

                    You would use .appliedObjectStyle = on that variable.

                    Or a method: .applyObjectStyle() where at least one argument, the object style must be fed to.*

                     

                    Hint, to denote an existing object style in a document that is not nested in a style group do:

                     

                    var nameOfObjectStyle = "NameOfObjectStyle";
                    var objectStyleThatShouldBeApplied = app.documents[0].objectStyles.itemByName( nameOfObjectStyle );
                    

                     

                    See into DOM documentation for applying an object style, do your edits, come back with some code if something is not working.

                    Adobe InDesign CS6 (8.0) Object Model JS: Rectangle

                     

                    Or you could execute method applyObjectStyle() on the frame holding the image:

                    Adobe InDesign CS6 (8.0) Object Model JS: Rectangle

                     

                    applyObjectStyle() comes with three arguments that could be fed to the method.

                    The first one you have to set, because it's not optional. That's the object style you want to apply. The other two are optional.

                     

                    *Basically that brings three options:

                    .applyObjectStyle( objectStyleThatShouldBeApplied , false, false )

                    .applyObjectStyle( objectStyleThatShouldBeApplied , true, false )

                    .applyObjectStyle( objectStyleThatShouldBeApplied , false, true )

                     

                     

                    All that said:
                    The most important question to you is: How is the variable named that denotes the frame that holds the image?

                    If you can answer that after looking into Kasyan's code the rest will be easy.

                     

                    Regards,

                    Uwe

                     

                    1 person found this helpful
                    • 7. Re: Remove All Missing Links with frames
                      wallaceh3639989 Level 1

                      Great! good explanation.