Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    indesign JS command "document.close" renders script useless - need help!

    hey guys,

    I have a (seemingly) fully working indesign script which opens up documents and indexes the contents.
    it puts out the index fine, as long as I do not close the documents.

    right now it
    - opens
    - analyzes
    - opens next
    - analyzes
    ....
    - spits out the index of all docs

    if I add a close in the loop after the analyze I get an Error 45 / Object is invalid alert on my index list

    Code:
    if (myFile != null) {
            try {
                //
                // main routine. documents are opened , analyzed, closed, next.
                for (x=0;x<myFile.length;x++) {
                    myOpenFile = myFile[x]
                    myDocument = app.open(myOpenFile);
                    mySearchPresets(); //also calls the search function and returns "myFoundList"
                    
                    app.activeDocument.close(); // if I leave out this line everything works great.
    
                    }
                } catch (e) {
                    alert ("Es ist ein Fehler beim Öffnen von\n" +myFile+ "\naufgetreten!\n\n" + e, "Fehler");
                    exit();
                }
    }
    after this it jumps to this function

    Code:
    function myArtNumList(){
        mySearchResultList = [];
        myFinalList = [];
        i = 0;
        a = 0;
        //converts text into integer
        //myArtNum= +myArtNum;    
        //alert ("ich sortiere");
        //alert (myFoundList[0]);
    while (i < myFoundList.length) {
        
        myArtNum = myFoundList[i].contents;  // this is the part I get the 45 error on ... 
        
    //  
    // sort and output is omitted here
    //
    any thoughts on this? thanks for your help!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    No idea what your myFoundtList contains, but if it contains *REFERENCES* to data in the document then of course the error makes sense.

    Possibly you need to clone the objects/text/whatever you find before putting it in myFoundList, so that the list references JS objects in memory instead of objects in the document.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    shootingpandas (03-20-2012)

  • #3
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks! that just might be it! it searches for different types of text and puts the results into "myFoundList". so I would probably end up with the reference to the text instead of the text itself.

    Do you have a quick hint how I could clone the contents so that the reference will get lost?

    EDIT: I'm on it. I just might have found a way...
    Last edited by shootingpandas; 03-20-2012 at 09:22 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Just do
    Code:
        var copy = new String( reference_to_contents );
    Or you can even simply do
    Code:
        var copy = "" + reference_to_contents;
    If the contents are other than a string, you can find ways to clone objects via google query: "javascript clone object"
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you so much! That was the hint I needed!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •