GʀᴜᴍᴘʏCᴀᴛ
GʀᴜᴍᴘʏCᴀᴛ

Reputation: 8920

How can I modify an InDesign's document textFrame created from InCopy?

I have an InDesign file that I'm trying to script through but I'm running into an issue. I believe a portion of the document's content was created from InCopy because when I try to modify that text frame after scripting through the pages I get a:

enter image description here

I do not have access to InCopy and I've tried overriding the InCopy frames by exporting the INDD file to an IDML file then bringing it back in but I'm unable to bypass InCopy. When I research the site the closest question I was able to find was How to script InDesign/InCopy to “Check In” and “Check Out” textFrames? but when I try to implement checkOut() onto the selection I get an error so I researched and ran across:

but I am still unable to insert on the selection text frame.

Trimmed down code

function run() {
    throw new Error( "Script has run into an error" ); 
}  
run.error = null;  

try {  
    app.doScript( somePages ); 
    if ( run.error ) { 
        throw run.error; 
    }
}  catch(e) {  
    alert( e );  
} 

function somePages() {
    var allPages = app.documents[0].pages.everyItem().getElements(),
        items = app.activeDocument.allPageItems,
        pageCount = allPages.length;

    for ( var x = allPages.length-1; x >= 0; x-- ) {
        if ( allPages[x].textFrames.length != 0  && items[x].locked == false ) {
            app.activeDocument.pageItems.everyItem().locked = false;
            app.select(allPages[x].textFrames[0].insertionPoints[0]);
            app.selection[0].contents= "foobar" + allPages[x].name;
        } 
    }
}

How can I script against a textframe to add text created from InCopy that will allow me to run through the document?

Upvotes: 0

Views: 968

Answers (1)

Loic
Loic

Reputation: 2193

That's because in a case of a text frame, what has to be checked out is the story.

function run() {
    throw new Error( "Script has run into an error" ); 
}  
run.error = null;  

try {  
    app.doScript( somePages ); 
    if ( run.error ) { 
        throw run.error; 
    }
}  catch(e) {  
    alert( e );  
} 

function somePages() {
    var allPages = app.documents[0].pages.everyItem().getElements(),
        items = app.activeDocument.allPageItems,
        pageCount = allPages.length;

    for ( var x = allPages.length-1; x >= 0; x-- ) {
        if ( allPages[x].textFrames.length != 0  && items[x].locked == false ) {
			app.activeDocument.stories.everyItem().checkOut();
            app.activeDocument.pageItems.everyItem().locked = false;
            app.select(allPages[x].textFrames[0].insertionPoints[0]);
            app.selection[0].contents= "foobar" + allPages[x].name;
        } 
    }
}

app.activeDocument.stories.everyItem().checkOut();

Upvotes: 3

Related Questions