Skip to main content
bagonterman
Inspiring
August 16, 2011
Question

Problem replacing content in text frame

  • August 16, 2011
  • 1 reply
  • 762 views

I am bumping my head against this. Its something I thought I know. I have a labeled text frame when I alert(mySpineTxt.getElements()); it tells me [object TextFrame] that sounds good to me then I use this

if(mySpineTxt.getElements().length != 0){
    with(mySpineTxt.parentStory.words.itemByRange(0,0)){
            mySpineTxt.contents=(String(myResp))
            }
        }

and it tells me that mySpineTxt does not support parentStory. I think it should.

Please add any corrections that I am missing.

This topic has been closed for replies.

1 reply

bagonterman
Inspiring
August 16, 2011

mySpineTxt has a value of [object PageItem] if i write mySpineTxt.getElements() returns [object TextFrame] wich i need I think i just need a way of writing the relationship of this text box however insertionPoints and parentStory does not work because they are not supported by object PageItem. I don't know what the right choice is.

bagonterman
Inspiring
August 16, 2011

In InDesign when you select the text box and go to menu object the content is grayed out. There would be no option for a menu command but I wonder why this is.

bagonterman
Inspiring
August 16, 2011

#targetengine "session"
//Creates a simple event listener.
main();
function main(){
    var myEventListener = app.addEventListener("beforePrint", dateChanges, false);
    var myEventListener = app.addEventListener("beforeSave", dateChanges, false);
    //var myEventKill = app.addEventListener("beforeClose", killDate, false);
}
///////////////////////////////////////////////
function dateChanges(){
     var myDocument = app.activeDocument;
var myPageItems = myDocument.pageItems.item("myDateLabel");
if(myPageItems==myPageItems){
if(myPageItems.getElements().length != 0){
    //alert ("I want to change your date")
    var myDateText=myPageItems
var myDate=new Date();
    myDate=String(myDate);
    myDate=myDate.slice(0,15);
    myDate=myDate.slice(4,15);
    alert(myDateText);
    with(myDateText.parentStory.words.itemByRange(2,4)){
                    contents=(    ""+myDate)
            }
        }
    }
}//ending bracket for dateChanges function
function killDate(){
app.removeEventListener("beforePrint", dateChanges, false);}

this is an event listner that changes the date. This works when I use myDateText.parentStory when I plug it in to the other script i am using same stuff. it doesn't work its object is also listed as a page item.