6 Replies Latest reply on Oct 23, 2008 4:47 AM by (Rasmus_Olsen)

    Understanding the object model yh

    Level 1
      Dear all,

      I'm building a simple PDF export script. Before exporting the script will search the flattenerpreset collection for a specific preset - if found use, else alert and exit. For this purpose I've located the class FlattenerPresets and the method "everyItem(): Array of FlattenerPreset". But when testing app.FlattenerPresets.everyItem(); I receive the error: Object does not support property or method 'FlattenerPresets'. 'Application' instead of 'app' gives me a different error: undefined is not an object.

      My apologies for bugging you gentlemen with another banality. PLease bear with the beginner :-)

      Sincerly,
      Rasmus
        • 1. Re: Understanding the object model yh
          Level 1
          Hi Rasmus,

          You can get a reference to the flattenerPresets like so:

          var myFlattenerPresets = app.flattenerPresets;

          myFlattenerPresets is a Collection and you can iterate through this Collection.


          var i = 0;
          while (i < myFlattenerPresets.length && myFlattenerPresets[i].name != thePref)
             i++;

          if (i == myFlattenerPresets.length)
             alert ("pref not found");


          The everyItem()-method return an Array that is iterable, however it ca be used to set a property of every item in a Collection.

          Good luck.

          Grtn, Kees
          • 2. Re: Understanding the object model yh
            Level 1
            Dear Kees,

            Muchos gracias :-)

            How do you know that you have to spell flattener with a 'f' and not a capitalize 'F' as the object model states?

            Sincerly,
            Rasmus
            • 3. Re: Understanding the object model yh
              Level 1
              The object model doesn't state that. Although it is very easy to misread it.

              When you refer to:

              app.flattenerPresets

              you're referring to the property of the application. That is spelled with a lowercase f in the object model.

              Now this property of the application is a FlattenerPreset object, and the name of the object has a capital F, but that comes up rarely in a script. For example, say, somehow, you were referring to an object and you didn't know what it was in some function in your script. You could check to see if it were a FlattenerPreset object by:

              if (myObj.constructor.name == "FattenerPreset")

              or even:

              if (myObj instanceof FlattenerPreset)

              notice that in both cases, you use the capital letter to refer to the object; in the second example, there are no quotes.

              But when you're addressing a property of the application that happens to be an object, the property name is what you need and that always starts with a lowercase letter:

              app.documents[0]; // a Document object
              app.documents[0].pages[0]; // a Page object

              etc.

              Dave
              • 4. Re: Understanding the object model yh
                Level 1
                Dear David,

                Your pedagogic effort are much appreciated. I've learned a lot from this thread, thank you gentlemen.

                Sincerly,
                Rasmus
                • 5. Re: Understanding the object model yh
                  Level 1
                  Dear David and Kees,

                  Do you have a hint on how to use the returned variable from my SelecFlattenerPreset function in my following exportSinglePages function? It appears that InDesign uses the flatterpreset defined in the joboptions file and not the string I serve to the app.pdfExportPreferences.appliedFlattenerPreset property.

                  function selectFlattenerPreset() {
                  try {
                  var myFlattenerPresets = app.flattenerPresets;
                  var thePref = "GWG_2400";
                  var i = 0;
                  while (i < myFlattenerPresets.length && myFlattenerPresets[i].name != thePref) i++; {

                  if (i == myFlattenerPresets.length) {
                  alert(thePref + " can't be found");
                  }
                  else {
                  return thePref;
                  }
                  }
                  }
                  }

                  function exportSinglePages() {
                  [snip variables]
                  for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
                  myPageName = myDocument.pages.item(myCounter).name;
                  app.pdfExportPreferences.pageRange = myPageName;
                  app.pdfExportPresets.appliedFlattenerPreset = "GWG_2400"; // <- returned variable goes here - but how?

                  myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFPreset);
                  }
                  }
                  • 6. Re: Understanding the object model yh
                    Level 1
                    Doh, I forgot the catch(e). I hope you get the picture. Pretty annoying that you can't do a copy/paste from ESTK to the browser without having the lines fly around like crazy :-)

                    Sincerly,
                    Rasmus