Skip navigation
winterm 176 posts
Sep 16, 2010
Currently Being Moderated

cleaning up text frames

Nov 1, 2011 3:56 PM

hello all you smart guys.

 

I get a big complex files from another designers every month for further processing. Among other not-so-good habits, they usually do not use layers.

To make layout a bit more organized, I move text to its own layer - simple task, have script for it. But it does the job straightforward - exactly 'as advertised' (Jongware's expression - I like it so )

 

Unfortunately, those designers didn't bother much with 'frame content' option. They can draw a frame with a text tool, fill it with color and use it as a background for some artwork or whatever...

my script 'text frames to separate layer' creates a mess on such pages, and locate it - not always is an easy task. Document usually has over 200 pages...

 

So, I'm dreaming about some magic script, which is able to "prepare" text for moving, I mean, to find and process:

 

case1: empty text frame with no fill/outline - remove (delete)

case2: empty text frame with any fill/outline - convert to 'unassigned'

case3: text frame with the same color applied to text and the frame itself (yes, it happens!) - well, maybe just 'select and stop'? I'm afraid it's too complicated to remove text from such a frame and then treat the frame as 'case2'?

 

any suggestions would be greatly appreciated...

 
Replies
  • Currently Being Moderated
    Nov 1, 2011 11:37 PM   in reply to winterm

    not sure myself, but have you checked this thread?

     

    http://forums.adobe.com/message/3306350

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 2, 2011 6:40 AM   in reply to winterm

    you need to check with textFrame properties.......

     

    if (myTextFrame.fillColor.name == None ) {

    alert("No Colors used");

    }

    else {

    alert("Colors applied on TextFrame);

    }

     

    try this..............

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 2, 2011 7:06 AM   in reply to winterm

    use this script it will help to remove only the empty text frame

     

     

    var myDocument = app.activeDocument;
    var myStories = app.activeDocument.stories.everyItem().getElements();
    for (i = myStories.length - 1; i >= 0; i--){
        var myTextFrames = myStories[i].textContainers;
        for (j = myTextFrames.length - 1; j >= 0; j--)    {
    var stroke = myTextFrames[j].strokeWeight;
    var color = myTextFrames[j].fillColor.name;
    //alert (color)
         if (myTextFrames[j].contents == "" && stroke == "0" && color == "None"){
               //alert ("yes") 
       myTextFrames[j].remove();
            }
        }
    }
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 3, 2011 2:44 AM   in reply to winterm

    @winterm:
    You can try this using script menu actions. This will only work, if the certain menu action is available.
    It is not available if there is contents in the text frame (e.g. a blank character) or (much more important from a scripters point of view) if a threaded text frame is empty because it's contents cannot fit inside it and it's contents is an empty string.

     

    Following code will single out empty text frames, select them and invoke a script menu action to set them to "Unassigned":

     

    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--){
            //If the contents of a text frame is an empty string:
            if(_storyAllTextFrames[m].contents === ""){
                _storyAllTextFrames[m].select();
                //Convert frame to "Unassigned":
                try{
                app.scriptMenuActions.itemByID(11297).invoke();
                    }catch(e){};
                };
            };
        };
     
    //Trick to deselect the last selection
    //Add a new textFrame, select and remove it:
    var _tempTextFrame = _d.textFrames.add();
    _tempTextFrame.select();
    _tempTextFrame.remove();
    

     

    @all: If there is a better way to deselect a selection please give an example…

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 3, 2011 5:43 AM   in reply to Laubender

    Hi Winterm,

     

    I've corrected Uwe's script a little bit.

    There is "contentType" property for text frame that can be changed.

     

    var _d = app.documents[0],
        _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--){
            if (_storyAllTextFrames[m].contents === "")
                _storyAllTextFrames[m].contentType = ContentType.UNASSIGNED;
        }
    }
    

     

    Uwe,

     

    To clear selection you can simply do this:

     

    app.select(null);
    

     

    or a little bit more complex:

     

    app.select(NothingEnum.NOTHING);
    

     

    Hope that helps.

     

    --

    Marijan (tomaxxi)

    http://tomaxxi.com

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 3, 2011 5:52 AM   in reply to Laubender

    1. Use ContentType:

     

     

    contentTypeContentType:
    ContentType.UNASSIGNED
    ContentType.GRAPHIC_TYPE
    ContentType.TEXT_TYPE
    r/wThe type of content that a frame can contain.

     

     

    _storyAllTextFrames[m].contentType = ContentType.UNASSIGNED;
    

     

    2. Use app.select:

     

    void select (selectableItems: varies[, existingSelection: SelectionOptions=SelectionOptions.REPLACE_WITH])
    Selects the specified object(s).

    ParameterTypeDescription
    selectableItemsArray of Objects
    NothingEnum
    Object
    SelectAll
    The objects to select. Can accept: Object, Array of Objects, NothingEnum enumerator or SelectAll enumerator.
    existingSelectionSelectionOptions:
    SelectionOptions.ADD_TO
    SelectionOptions.REMOVE_FROM
    SelectionOptions.REPLACE_WITH
    The selection status of the Application in relation to previously selected objects. (Optional) (default:SelectionOptions.REPLACE_WITH)

     

     

    app.select(NothingEnum.NOTHING);
    

     

    (Edit: Hi Marijan!)

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 3, 2011 7:44 AM   in reply to Marijan Tompa

    Thank you, Marijan & Jongware to point to the right property "contentType" and to app.select(null).

    I think the line:

     

    _storyAllTextFrames[m].contentType = ContentType.UNASSIGNED;
    


    needs a try-catch-wrapper:

     

    try{
        _storyAllTextFrames[m].contentType = ContentType.UNASSIGNED;
        }catch(e){};
    

     

    It could be that a threaded text frame has no contents because the contents is too big to fit inside.
    contents === "" will perfectly match such an empty text frame, but you cannot asign a new contentType to it.
    See my screen shot:

    ContentsOfThreadedTextFrameIsEmptyString.png

     

    Uwe

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points