CS3/4, JS Amateur question: how remove all empty text frames?

I'm an amateur, and thought it would be a straightforward matter to write a script that simply deletes all empty text frames in all of a document's stories. Here's my second attempt:
var myDocument = app.activeDocument;
var myStories = myDocument.stories;
for (i = 0; i < myStories.length; i++){
  var myStory = myStories[i];
  var myTextFrames = myStory.textContainers;
    for (j = myTextFrames.length - 1; j >=0; j--) {
    if (myTextFrames[j].contents == "") myTextFrames[j].remove();
The trouble is, sometimes it works as intended, but sometimes, with multiple stories, it needs to be run more than once. Can anyone explain why that is?
Thanks -- Jeremy

[Jongware] wrote:
(Bit of a Johnny-come-lately, but anyway )
AHA! -- This is a great help. It was driving me up the wall, and I don't know why it didn't work for me last night. Maybe it's because I was counting through stories in the wrong direction. Anyhow, I see how it works now, and I'm very grateful for the help.
By the way Harbs, I used all three of your suggestions because I had spent far too much time tapping away at that nut with my little toy hammer. I vented my frustration by using all three of your sledgehammers. In particular, I made sure it left a single empty text frame where it was, as such a frame might be used as a graphic. (Although in the past, I've found an empty story can be a sneaky place for a rogue font to hide. The insertion point just in front of the "end of story" character can have a paragraph style applied, with its associated font, but "Find" won't find any characters with that paragraph style or font applied!)
Thanks to all again -- Jeremy

Similar Messages

  • I recently updated my OS to OS X. I had to update my word and powerpoint etc... to 2011 version, but now when I want to open a .doc file made in word 2003 it removes all the text in it! I did not back anything up!

    I recently updated my OS to OS X. I had to update my word and powerpoint etc... to 2011 version, but now when I want to open a .doc file made in word 2003 it removes all the text in it! I did not back anything up! All my mums work is on there for her job and now she cant use it! I need help fast!

    If you updated from 2003 that must be on a Windows machine, can you recover them from there?

  • How do I delete all empty graphics frames from a document?

    I have data merged a document and need to remove all the empty graphics frames as quick as possible.
    I have found solutions for deleting empty text frames but not graphics frames. Can somebody help with this as it will save soo much time and RSI!
    I found an applescript solution here:
    http://forums.adobe.com/thread/756281
    However, I am running Windows 7 and Id CC
    Cheers,
    Kris.

    Hi MToys
    I added a little to the script so that it will work on Ovals and Polygons also. [Not TextFrames]
    You just have to set the values for which of the frame types you want to delete.
    You can do this by setting the const values at the top of the script for DeleteRectangle, DeleteOvals, DeletePolygons
    There are a few uncertainties that I had:
    If an object is selected, should the script only delete that objects frame type.
    I.e., If you select an oval, should the script know to delete only ovals.
    At this point, I did not do that, rather it will just get the settings from the selected object, and delete all frame types with those settings
    I had to disable matching the transparency settings because they werent comparing correctly between different frame types
    Meaning, I made 3 frames, Oval, Rectangle and Polygon - no settings applied.
    I selected the oval and ran the script. It only deleted the oval even though set it to delete all.
    I found that the transparency settings werent matching... even though there werent any
    So, for now - its disabled.
    If someone can shed some light on this I would appreciate it.
    I tested the script on Mac Mountain Lion - ID CS6 and seems to work well
    Here is the script
    const Object_Style = false,
        Fill_Color = true,
        Fill_Tint = true,
        Fill_Transparency_Settings = true,
        Item_Layer = true,
        Stroke_Color = true,
        Stroke_Weight = true,
        Stroke_Type = true,
        Stroke_Transparency_Settings = true,
        Stroke_Tint = true,
        Stroke_Alignment = true;
    const DeleteRectangles = true,
        DeleteOvals = true,
        DeletePolygons = true;
    app.doScript(main, undefined , undefined, UndoModes.fastEntireScript, "INSERT_HERE_THE_SCRIPT_NAME")
    function main() {
        var myDoc = app.activeDocument;
        var mySel = app.selection;
        if (mySel.length > 0) {
            mySample = app.selection[0];
            if (mySample.constructor.name == "Rectangle" ||
                mySample.constructor.name == "Oval" ||
                mySample.constructor.name == "Polygon")
                var isSample = true;
                var objSty, fClr, fTint, fTrans, lay, sClr, sWeight, sType, sTrans, sTint, sAlign;
                GetProps(mySample);
        if (DeleteRectangles) {DeleteItems(myDoc.rectangles)}
        if (DeleteOvals) {DeleteItems(myDoc.ovals)}
        if (DeletePolygons) {DeleteItems(myDoc.polygons)}
        function DeleteItems(myGraphicFrames) {
            for (var i = myGraphicFrames.length-1; i >= 0; i--) {
                if (myGraphicFrames[i].graphics.length < 1) {
                    myGraphicFrames[i].select();
                    if (isSample) if (!checkProps(myGraphicFrames[i])) continue;
                    myGraphicFrames[i].remove();
        // ======================================
        function GetProps(mySample) {
            objSty = mySample.appliedObjectStyle;
            fClr = mySample.fillColor;
            fTint = mySample.fillTint;
            fTrans = mySample.fillTransparencySettings;
            lay = mySample.itemLayer.name;
            sClr = mySample.strokeColor;
            sWeight = mySample.strokeWeight;
            sType = mySample.strokeType;
            sTrans = mySample.strokeTransparencySettings;
            sTint = mySample.strokeTint;
            sAlign = mySample.strokeAlignment;   
        // ======================================
        function checkProps(myFrame) {
            var i=0;
            if (Object_Style) if (myFrame.appliedObjectStyle != objSty) return false;
            if (Fill_Color) if (myFrame.fillColor != fClr) return false;
            if (Fill_Tint) if (myFrame.fillTint != fTint) return false;
            if (Item_Layer) if (myFrame.itemLayer.name != lay) return false;
            if (Stroke_Color) if (myFrame.strokeColor != sClr) return false;
            if (Stroke_Weight) if (myFrame.strokeWeight != sWeight) return false;
            if (Stroke_Type) if (myFrame.strokeType != sType) return false;
            if (Stroke_Tint) if (myFrame.strokeTint != sTint) return false;
            if (Stroke_Alignment) if (myFrame.strokeAlignment != sAlign) return false;
            //if (Stroke_Transparency_Settings) if (myFrame.strokeTransparencySettings != sTrans) return false;
            //if (Fill_Transparency_Settings) if (myFrame.fillTransparencySettings != fTrans) return false;
            return true;

  • How to access the Text Frame, when we use scrollable frame,

    Hi Friends,
    How to access the Text Frame, when we use scrollable frame,
    Thank you,
    [ Nav ]

    That's the same question:
    how can I access something (a page item) on a page…
    Answer: you need something unique in that object you can get a handle on.
    Or you use the selection a user of your script is doing and work with that selection…
    A "scrollable frame" is nothing special. What it makes it a "scrollable frame" is the DPS software.
    So you have to look for attached labels on the object, that identify the object for the PDS plug-in "Overlay Creator" as a "scrollable frame". That's possible with the "extractLabel("KeyString")" function. But you need to know the appropriate key-string in advance.
    In another of your thread in the DPS forum, I basically answered the question how to obtain those key-strings.
    When knowing the key-string you could loop through all your page items (you can skip all text frames) in the allPageItems-collection, to identify the "scrollable frame" by extracting the right label.
    If you have more than one "scollable frames" you need a second unique identifier for the particular object.
    That could be nearly any property.
    Keep in mind, there is no "scrollableFrames" collection in the DOM !
    Uwe

  • How to Create a text frame?

    Hai
    i'm senthil....
    i'm just now started working with Adobe Indesign plugin's..
    Can anyone tell me how to create a text frame...
    wat r the steps for creating a text frame?
    what are the Interface pointers used for creating a text frame...
    plzz reply me who knows...
    bye.

    See SDKLayoutHelper::CreateTextFrame.
    You can also look at SnpCreateFrame::CreateTextFrame in SnippetRunner.
    Regards,
    Narayan

  • Select all Linked Text Frames

    Dear All,
    My Request:
    1. Is it possible to select all linked text frames of my selecting text frame (Please refer attachment)
    2. Suppose If we select all text frames, is it possible to fix height for all text frames like as 3p or 4p etc....
    Trying script for select all linked text frames:
    if (app.selection[0].nextTextFrame == null)
       if (app.selection[0].previousTextFrame != null)
            alert("pass")
            app.select(previousTextFrame.parent) && app.select(nextTextFrame.parent) && app.select(startTextFrame.parent)
    Could you anyone give solution for my request.
    Thanks in advance
    Beginner

    Hi All,
    If I select any text frame, I need to select all linked text frames of selecting text frame.
    Please can anyone help me...
    Please refer the above screenshot for your reference.
    Trying script:
    if (app.selection[0].nextTextFrame == null)
       if (app.selection[0].previousTextFrame != null)
          myParagraphs = app.selection[0].parentStory.paragraphs;
          for (j=0;j<myParagraphs.length;j++)
            myParentTF = myParagraphs[j].parentTextFrames[0].contents
            alert(myParentTF)
    Output i needed:
    Thanks in advance
    BEGINNER

  • Script to select all overflow text frames and fit them to content?

    I have a document with several text frames that have overset text, due to replacing a font.  I was looking for a script that would:
    1. find all the text frames that have overset text
    2. apply "fit frame to content" command for each of these
    Can anyone please help me here?  I'm trying to learn scripting but some of these things still confuse me.  Thanks.

    hi,
    give a try to this js code:
    var _d = app.documents[0];
    var _allStories = _d.stories;
    for(var n=_allStories.length-1;n>=0;n--){
    var _storyAllTextFrames = _allStories[n].textContainers;
    for(var m=_storyAllTextFrames.length-1;m>=0;m--){
    _storyAllTextFrames[m].select();
                //Fit Frame to Content:
                try{
                app.scriptMenuActions.itemByID(11291).invoke();
                    }catch(e){};
               try{
               app.scriptMenuActions.itemByID(278).invoke();
                    }catch(e){};
    Disclaimer:
    I'm NOT a scripter. Sorry, don't remember exact origin of this code, but it works...

  • How to find associated text frame with XML element?

    Hello experts, I am new to InDesign CS SDK and have a question.
    I am building an Extension to import an XML document into an InDesign template. As the content in XML can be unpredictable, in the Extension, I want to loop through all the XML elements and make sure it has associated text frames, and if it doesn't, I want to create a text frame and set the content to the text frame.
    I think I figured out how to create a new text frame in page and set the content in the frame, but I am having difficulty finding an associated text frame for an XML element.
    If anyone has a sample code finding a text frame for an XML element, I appriciate it. Or if anyone can tell me what document I need to look, it will be great too.
    Thanks,

    Here's a code snipet with null checks removed:
    UID MyClassName::GetFrameForXMLElement(IIDXMLElement* inXMLElement)
        InterfacePtr< ITextModel > textModel( Utils< IXMLUtils >()->QueryTextModel( inXMLElement ) );
        InterfacePtr< IFrameList > frameList( textModel->QueryFrameList() );
        UID aFrameUID = frameList->GetNthFrameUID( 0 );
        return aFrameUID;

  • How to select a text frame that has been "Sent to Back"?

    Hi Framers,
    In FM 7.2 (all patches up to date, running on Windows XP Pro), I added a note inside a text frame next to an anchored frame holding an image. I nudged the text frame close to the image but it blocked out a tiny portion of the image. So I selected the text frame and from the Graphics menu clicked Send to Back.  Solved that problem, of course. Now I want to change the wording in the note but can't do it because the entire text frame has been sent to back -- how can I select it to Bring to Front so I can edit its contents???
    This MUST be something totally obvious, right?  Can I plead pre-holiday brain freeze?
    TIA,
    Gay

    galson wrote:
    Hello again, Sheila ;~)
    I selected all and moved my cursor all around the page (around various pages, actually, since Ctrl+A selects the entire chapter), and I see what you mean by the color of the arrow's head changing between black and white. Is it significant that the ONLY time it's black is when I'm outside the frame of the page itself? (That is, in the white, non-editable space around the actual frame borders on the page.) Clicking anywhere, whether inside or outside the active area, deselects everything.
    HOLD THE PRESSES!  Even though I *knew* I hadn't grouped my text frame with anything else, after reading your suggestion, I selected the page frame to make sure I hadn't somehow grouped it with my text frame: I hadn't -- but then, on a hunch, I sent IT (the page frame) to the back -- now I can select the text frame!
    I'm marking your response as answering my question and I'm also going to try to mark Peter's the same way, because each of you in your own way, helped me resolve this problem.
    Thank you both and HAPPY HOLIDAYS!  (Gee, and I didn't get either of you anything... maybe next year  ;~))
    Gratefully,
    Gay
    Hi, Gay:
    The "I-Beam" pointer tool is called the Smart Pointer, because it changes to an I-beam when it's over text, and to the Graphics Pointer tool when over a graphic, or part of a graphic, or when you press Ctrl. It's easy to select the main text frame when you Ctrl+click on its interior text area inadvertently, when you're trying to select an anchored frame edge, or when you use Ctrl+A to select all. It's frustrating to have some of these unintended events happen when you're not expecting them. Always work with View > Borders ON, to display the edges of objects and reduce confusion, and always watch where you click. You can zoom iin to large magnification to see things better.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • How to ignore empty text element while using DOM to parse xml??

    hi everyone,
    i am using DOM to parse an xml file. But i dont know how to cinfig the DocumentBuilderFactory to ignore empty text elements.
    For example, i have an xml file like this:
    <?xml version="1.0" encoding="UTF-8" ?>
    <root>
        <child>Tom</child>
        <child>Jerry</child>
    </root>I used the following codes to parse:
    String fname = "Tom-and-Jerry.xml";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setIgnoringElementContentWhitespace(true);
    factory.setIgnoringComments(true);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    // Generate a DOM tree from the DOM builder.
    org.w3c.dom.Document dom = builder.parse(new File(fname));
    org.w3c.dom.NodeList list = dom.getChildNodes();
    for (int i=0; i<list.getLength(); i++) {
        System.out.println("Child No."+i);
        System.out.println("NodeName="+list.item(i).getNodeName());
        System.out.println("NodeType="+getType(list.item(i).getNodeType()));
        System.out.println("NodeValue="+list.item(i).getNodeValue());
        System.out.println();
    }The result is not exactly what i want ---- there are 5 children in list!! The 1st, 3rd and 5th are #text and their values are all empty. Only the 2nd and the 4th are the child that i expect.
    It is really troublesome to get all these silly empty texts as sub elements. I tried to get rid of them, but i failed. I just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.
    Anyone can help me? thanks.
    Heavy ZHENG

    I just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.That only does something if the XML has a DTD that enables it to know what whitespace can be ignored and what is significant. The API documentation for the method refers you to this document:
    http://www.w3.org/TR/REC-xml#sec-white-space

  • How to resize margins / text frames for a whole book?

    Hello, I am new to InDesign, but not Adobe software. I am trying to use InDesign to produce a book I have written for a university course I teach. I have 33 documents all together as an InDesign book. After I printed out some test pages I thought there should be more white space on all sides. I changed the margins by 5mm in the master page on the master document and then synced the book. Now the MARGINS have changed on all the documents, but the TEXT FRAMES remain unchanged. I know that I can change text frame sizes, by hand, but that would take forever. I can't find how I can automatically resize a whole book. Is this not possible?
    Craig

    Before synching, you need to enable layout adjustment in each document (Layout > Layout adjustment). Since you have 33 documents, you might want to run this little script to do it for you:
    for (i = 0; i < app.documents.length; i++)
    app.documents[i].layoutAdjustmentPreferences.enableLayoutAdjustment = true;
    Open all the documents where Layout adjustment should be enabled and run the script.
    Peter

  • How to Embed a Text Frame Within a Text Frame with Smart Text Reflow

    This is driving me nuts, and I've wasted hours searching exhaustively but can't seem to find the answer.
    I've been working with this indesign file and cleaning it up really well.  I now have all the text flowing with smart text reflow.  There are two parts in the book that have columns of information, or tables.  The way it was originally done was having a text box placed inside the text box.  But unfortunately, whenever you add pages before or after, the text box won't follow with the text box it is inside.  I have tried grouping the two text boxes together, but this doesn't seem to work with Smart Text Reflow (since every page is based on the primary master). How do you embed a text frame inside another text frame that is based off the primary master?  I guess it would be like using the text frame as an object. 
    I included an image to help my explanation.
    I even tried adding columns and then spannign the header part across, but this still doesn't flow with the rest of the text.

    ANchor it into the other text fram, look in the help file. Keyword = Anchored Objects.

  • How to create empty text box in wad

    hi
    can i get step by step process for create empty text box user need to enter some text after wad execution or i need keep default tex also?
    please let me know#

    Hi
    can you give me more clarification please?
    i have 1 report
    comp code material plant qty
    i am using variable as comp code
    if i give variable comp code as 1000
    i want get output and at report right side   i want see variable    comp code: 1000
    how can i ge this ple?
    regards
    suneel.

  • How to create empty text file on target system for empty source text file

    Hi All,
    I have an issue in handling empty file in the Text (FCC) to Text (FCC) file scenario. Interface picks text file and delivers on target system as text file. I have used FCC in both sender and receiver CCs.
    Interface is working fine if the source file is not empty. If the source text file is empty (zero Bytes), interface has to delivery an empty text file on target system.  I have setup empty file handling options correctly on both CCs.
    But when I tried with an empty file I am getting the error message 'Parsing an empty source. Root element expected!'.
    Could you please suggest me what I need to do to create an empty text file on target system from empty source text file?
    Thanks in Advance....
    Regards
    Sreeni

    >
    Sreenivasulu Reddy jonnavarapu wrote:
    > Hi All,
    >
    > I have an issue in handling empty file in the Text (FCC) to Text (FCC) file scenario. Interface picks text file and delivers on target system as text file. I have used FCC in both sender and receiver CCs.
    > Interface is working fine if the source file is not empty. If the source text file is empty (zero Bytes), interface has to delivery an empty text file on target system.  I have setup empty file handling options correctly on both CCs.
    >
    > But when I tried with an empty file I am getting the error message 'Parsing an empty source. Root element expected!'.
    >
    > Could you please suggest me what I need to do to create an empty text file on target system from empty source text file?
    >
    > Thanks in Advance....
    >
    > Regards
    > Sreeni
    the problem is that when there is an empty file there is no XML for parsing available. Hence in case you are using a mapping it will fail.
    What ideally you should do is to have a module that will check if the file is empty and if so write out an XML as you want with no values in the content/fields.
    Or the next choice would be to have a java mapping to handle this requirement. I guess that on an empty file the java mapping will go to an exception which you can handle to write out your logic/processing

  • Removing empty text frames

    trying to remove any text frames with empty content but it doesn't seem to be removing correct textFrame layers, any idea what I might be doing wrong?
    var numberOfEmptyTextBoxes = 0;
    var layersWithNoText = new Array();
    if ( app.documents.length > 0 ) {
        for ( i = 0; i < app.activeDocument.textFrames.length; i++ ) {
            text = app.activeDocument.textFrames[i].textRange;
            numWords = app.activeDocument.textFrames[i].words.length;
            if (numWords == 0){
                      layersWithNoText.push(i);
                numberOfEmptyTextBoxes++;
        if(numberOfEmptyTextBoxes > 0){
                  alert("WARNING you have " + numberOfEmptyTextBoxes + " empty text boxes");
        alert("layers with no text:" +layersWithNoText);
        removeTextLayersWithNoContent(layersWithNoText);
    function removeTextLayersWithNoContent(layersWithNoText) {
              var layersWithNoText = layersWithNoText;
              for (var i = 0; i < layersWithNoText.length; i++) {
                        var currentIndex = layersWithNoText[i];
                        alert("current index: "+currentIndex)
                        app.activeDocument.textFrames[currentIndex].remove();

    yes, to do it like that, you would have to loop backwards to remove the textframes and not mess up with the indexes,
    or, push the textframes into your array like this
    var numberOfEmptyTextBoxes = 0;
    var layersWithNoText = new Array();
    if ( app.documents.length > 0 ) {
        for ( i = 0; i < app.activeDocument.textFrames.length; i++ ) {
            text = app.activeDocument.textFrames[i].textRange;
            numWords = app.activeDocument.textFrames[i].words.length;
            if (numWords == 0){
                      //layersWithNoText.push(i); // don't push the indexes
                      layersWithNoText.push(app.activeDocument.textFrames[i]); // push the actual text frames
                numberOfEmptyTextBoxes++;
        if(numberOfEmptyTextBoxes > 0){
                  alert("WARNING you have " + numberOfEmptyTextBoxes + " empty text boxes");
        alert("layers with no text:" +layersWithNoText);
        removeTextLayersWithNoContent(layersWithNoText);
    function removeTextLayersWithNoContent(layersWithNoText) {
              var layersWithNoText = layersWithNoText;
              for (var i = 0; i < layersWithNoText.length; i++) {
                        var currentIndex = layersWithNoText[i];
                        alert("current index: "+currentIndex)
                        //app.activeDocument.textFrames[currentIndex].remove(); // removing 1 item re-indexes the remaining items
                        layersWithNoText[i].remove(); // remove the textframes in the array, regardless of actual index

Maybe you are looking for

  • File content conversion for File Reciever

    Hi, I am working on Idoc to file scenario. I need the file in the format which doesnt have have separators between the fields. I used the follwing FCC: HeaderRecord.addHeaderLine HeaderRecord.fieldFixedLengths     1,1,10,2,4,12,3,1,9,1,4,1,1,1,2,1,4,

  • JTable Horizontal Scroll WHEN NEEDED fix?

    Me again.... JTable in a JScrollPane When the Jtable width exceeds the scrollpane I would like a horizontal scrollbar to appear. If the Jtable does not exceed the width Id like it to fill the ScrollPane. If I use the AUTO_RESIZE_OFF I get a horizonta

  • DBMS_XDB.createResource(path, XMLTYPE) removes the XML declaration

    Hi, I'm writing out XML documents to the XMLDB repository by looping through a view which has an XMLTYPE column and writing each instance of that column using the 2nd form of createresource specified in the PL/SQL Packages and Types Reference. DBMS_X

  • WPA2 support for c6380

    I'm thinking in buying a c6380 wireless printer. Does it support the following setup? Auth> WPA2-psk Encryption>AES In the specs, it doesn't show WPA2 support, only WPA and WEP with AES encryption. I guess it's supported as it is the standard nowaday

  • My Imac won't boot up. It is stuck on apple logo with spinning gear.

    My Imac won't boot up. It is stuck on apple logo with spinning gear. It will not boot in safe mode, my install disc will not read and fsck wont fix it.. I can hear the hard drive spinning. So i know my drive is not bad.. Right before this happened i