Copy link to clipboard
Copied
Hi,
since the flex layout is a brand new feature in InDesign, it is difficult for me to find anything about using scripts with it.
This page states that "flex layout is scriptable", however it links to InDesign ExtendScript API documentation, where I could not find even a mention of this flex layout (I believe it is just a question of few weeks).
Still - could any of you give me an advice, how to change content of a text frame, that is connected into a flex-layout object?
I have got my script working with simple (normal) text frames, now the flex-layout frames are ignored.
var tfs = page.textFrames;
var i = tfs.length;
while(i--) {
if (tfs[i].contents == "search_string") {
tfs[i].contents = "replace_string";
}
}
Thank you very much for your hints.
Honza
Hi @Honza5CEF ,
consider a flex layout a special container object. Like a group for example.
So page.textFrames will not get text frames inside that container object.
What can you do?
Get all page items on the page and sort out the ones that are text frames.
// Get all page items on page:
var allPageItemsArray = page.allPageItems;
// Loop the array:
for( var n=0; n<allPageItemsArray.length; n++ )
{
if
(
allPageItemsArray[n].constructor.name == "TextFrame" &&
allPageItemsArray[n].cont...
Copy link to clipboard
Copied
Hi @Honza5CEF ,
consider a flex layout a special container object. Like a group for example.
So page.textFrames will not get text frames inside that container object.
What can you do?
Get all page items on the page and sort out the ones that are text frames.
// Get all page items on page:
var allPageItemsArray = page.allPageItems;
// Loop the array:
for( var n=0; n<allPageItemsArray.length; n++ )
{
if
(
allPageItemsArray[n].constructor.name == "TextFrame" &&
allPageItemsArray[n].contents == "search_string"
)
{
allPageItemsArray[n].contents = "replace_string";
}
};
Kind regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Hi @Honza5CEF ,
what will you get by an alert that is asking for the parent of a selected object (e.g. a text frame) that is part of a flex layout?
// Object, eg. a text frame, inside a flex layout selected.
alert( app.selection[0].parent.constructor.name );
You could get all available properties and available values of the parent :
// Select an object inside a flex layout
// Get all property/value pairs of the parent of the selected object
// Write them to a new text frame of the same page
var page = app.selection[0].parentPage;
var parentOfSelection = app.selection[0].parent;
var resultFrame = page.textFrames.add( { geometricBounds : page.bounds } );
var propsContents = parentOfSelection.constructor.toString() +"\t"+ parentOfSelection.constructor.name +"\r" ;
var props = parentOfSelection.properties;
for( x in props )
{
try{
propsContents = propsContents + x +"\t"+ props[x].toString() +"\r" ;
}catch(e)
{
propsContents = propsContents + x +"\t"+ e.message +"\r";
}
}
resultFrame.parentStory.contents = propsContents;
Kind regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
I have manually searched thru an own object model view for "Flex".
Page items have a flexObjects collection and two related properties.
There is a new page item derived class FlexObject:
Some methods that suggest the implementor did not like InDesign concepts such as collections, LocationOptions etc.
ObjectStyle has a new section that can get enabled
Here the attributes, should be the same as in page item
Several related enums
They should really have used AutoEnum instead of the latter, but yeah …
Almost missed this Application property (no matching Document property!):
also makes me wonder what they mean with "canvas"
Document, Spread, Page also have a flexObjects collection
Copy link to clipboard
Copied
Sorry, should have made that a separate thread.
Anyway, for the text frames within flex it should be possible to descend from page.flexObjects collection, for each then use its allPageItems array as Uwe suggested, but there are also collections for textFrames, endnoteTextFrames and so forth. Of course everything could again be nested, also within groups or another level of flexObjects.
I haven't yet tried any script, just looking at the object model.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now