0

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?

RobC
  • 22,977
  • 20
  • 73
  • 80
DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

1 Answers1

3

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();

Loic
  • 2,173
  • 10
  • 13
  • Thanks for the answer but still not working. I still get the same issue as mentioned above, with the select and it throws an error. The exact error: "value for parameter 'selectableItems of method 'select'. Expected Object, Array of Objects, NothingEnum enumerator or SelectAll enumerator, but received nothing.'" – DᴀʀᴛʜVᴀᴅᴇʀ Mar 15 '17 at 15:59
  • FWIW you don't need to select object in order to change contents. try to remove the line. – Loic Mar 15 '17 at 16:15
  • if I did that then I cant insert text into the frames which is what I'm trying to do – DᴀʀᴛʜVᴀᴅᴇʀ Mar 15 '17 at 16:26
  • I don't think your issue is related to that call as you can edit object properties without the urge of selecting it. – Loic Mar 15 '17 at 17:08