1 Reply Latest reply on Apr 8, 2016 8:53 PM by S Hopkins

    Create document based on intent options

    JulianFT

      Hi all,

       

      I'm trying to check whether a document has the intent option set to digital publishing, and if not, create a new one that has that option. I tried the script below, but that doesn't seem to work as intended. Any suggestions would be highly appreciated!

       

      Kind regards,

       

      Julian

       

      
      
      
      
      function createDocument(){   
       
      
      
           
       
      
      
              
      try{
      
      
      
      
      
      
      
                  
      // Check to see if a document is open; if not, create it under the catch
      
      
                  
      var myDocument = app.activeDocument; 
      
      
                  
      var myDocumentPreset = app.documentPresets.add();
      
      
                  
      myDocumentPreset.createPrimaryTextFrame = true;
      
      
                 
       
      
      
                  
      // Check to see if the open document is meant for digital publishing. If not, create a new one.
      
      
                  
      if (myDocument.documentPreferences.intent != DocumentIntentOptions.DPS_INTENT){
      
      
                      
      var myDocument = app.documents.add({documentPreset:myDocumentPreset}); 
      
      
                      
      myDocument.documentPreferences.intent = DocumentIntentOptions.DPS_INTENT;
      
      
                      
      alert(myDocument.documentPreferences.intent);
      
      
                      
      }
      
      
                 
       
      
      
                  
      }
      
      
             
       
      
      
              
      catch(e){
      
      
                   
      var myDocument = app.documents.add({documentPreset:myDocumentPreset}); 
      
      
                   
      myDocument.documentPreferences.intent = DocumentIntentOptions.DPS_INTENT;       
       
      
      
                   
      }
      
      
          
      }
      
      
      
      
      
      
      
      
      
        • 1. Re: Create document based on intent options
          S Hopkins Adobe Community Professional

          I don't see a problem with the exception that you are not calling the function.

          createDocument();

          function createDocument() {

             etc.

          }

           

          I might suggest that you don't create the document preset until you need it, for example:

          checkDocument();

          function checkDocument() {

            try {

                var myDocument = app.activeDocument;

               if (myDocument.documentPreferences.intent != DocumentIntentOptions.DPS_INTENT) {

                  myDocument = newDocument();

              }

          } catch (e) {

                   myDocument = newDocument();

          }

          }

          function newDocument() {

              var myPreset = app.documentPresets.add();

              myPreset.createPrimaryTextFrame = true;

              var myDocument = app.documents.add({documentPreset:myPreset});

              myDocument.documentPreferences.intent = DocumentIntentOptions.DPS_INTENT;

              return (myDocument)

          }