Selecting textFrames inside of a group in InDesign CS6

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 04:24:22

问题


Similar to my earlier problems with finding a textFrame on a page based on its geometricBounds or by part of its name, I now am running into the problem of finding textFrames if they are inside groups. If I use an array of all textFrames, such as:

var textFramesArray = document.textFrames.everyItem().getElements();

it will not find any textFrames that are inside of a group. How can I figure out how to reference a textFrame if it's inside a group? Even if the group has to be un-grouped, that's fine, but I cannot even figure out how to find groups on the page!


回答1:


Groups on a page are page.groups ... but you don't need this anyway. Fabian's answer is good, but it doesn't take groups-in-groups into account -- nor clipping masks, nor text frames inside tables and footnotes (etc.).

Here is an alternative approach: allPageItems is pretty much guaranteed to return all page items, of all kinds and persuasion, inside groups or other frames or whatnot. You can inspect, then process, each of them in turn, or build an array of text frames to work with at leisure:

allframes = app.activeDocument.allPageItems;
textframes = [];
for (i=0; i<allframes.length; i++)
{
    if (allframes[i] instanceof TextFrame)
        textframes.push(allframes[i]);
}
alert (textframes.length);



回答2:


Try this:

// this script needs:
// - a document with one page
// - some groups with textframes in it on the first page

var pg = app.activeDocument.pages[0];
var groups = pg.groups;

var tf_ingroup_counter = 0;
for(var g = 0; g < groups.length;g++){
    var grp = groups[g];

        for(var t = 0; t < grp.textFrames.length;t++){
            var tf = grp.textFrames[t];
                if(tf instanceof TextFrame){
                    tf_ingroup_counter++;
                    }             
        }
    }

alert("I found on page " + pg.name +"\n" + pg.textFrames.length 
            +" textframes\nOh and there are also "
            +tf_ingroup_counter+ " hidden in groups");



回答3:


Your task to get all the text frames in the layer or the document. Whether those text frames are in a group or not. This is done through the property of allPageItems. For instance use this:-

var items=app.activeDocument.allPageItems;

this will give you all the text frames in the item and within group also. Now you can do any manupulations. You can check the items on the debug console which will give all the types of the objects.And then you can check for the textframe

items[i].constructor.name =='TextFrame'

and now you can store each object in type array.



来源:https://stackoverflow.com/questions/17685388/selecting-textframes-inside-of-a-group-in-indesign-cs6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!