15 Replies Latest reply on Dec 4, 2012 5:52 AM by Trevorׅ

    Where are withProperties arguments outlined?

    McShaman Level 1

      One of the biggest problems I have with the Adobe scripting API and ESTK is that the documentation is either poor and incomplete or that it assumes a level of knowledge that I just don't have.

       

      There are many methods that use an argument <code>withProperties</code>

       

      For example:

       

      <pre>app.documents.add(showingWindow, documentPreset, withProperties)</pre>

       

      I assume this argument can be passed object or associtative array with a series arguments to be used when the method is run. However I cannot find any information in the documentation or online that outlines the syntax to use for these arguments and what properties can be applied.

       

      Can somebody please explain how I would find this information?

        • 1. Re: Where are withProperties arguments outlined?
          bgfrhlp

          Most of the document properties are readonly as you can find out at http://jongware.mit.edu/idcs5js/pc_Document.html.

           

          Here is an example of properties in use.

          app.documents.add({zeroPoint:[100,344], label:"NEW"}); 

           

          Grant Gamble's Indesign CS5 JavaScript is a good source.

          • 2. Re: Where are withProperties arguments outlined?
            [Jongware] Most Valuable Participant

            McShaman179 wrote:

             

            One of the biggest problems I have with the Adobe scripting API and ESTK is that the documentation is either poor and incomplete or that it assumes a level of knowledge that I just don't have.

            There are many methods that use an argument <code>withProperties</code>

             

            If you're just starting out, don't break your head over the 'withProperties' stuff. You can safely ignore it, and use the regular way to set the properties. To copy bgfrhlp's example:

             

            Here is an example of not using "with Properties":

             

            var myDoc = app.documents.add();

            myDoc.zeroPoint = [100,344];

            myDoc.label = "NEW";

             

            bfgrhlp wrote:

            Most of the document properties are readonly ..

             

            Not entirely a problem, as you can work around that for properties that are objects and thus have properties of their own. This works:

             

            app.documents.add({documentPreferences:{pageHeight:"10cm", pageWidth:"20cm"}});

             

            .. but don't get too greedy, because at some point it stops working:

             

            app.documents.add({marginPreferences:{left:"0.5in", right:"0.5in", top:"24pt", bottom:"36pt"}, documentPreferences:{pageHeight:"10cm", pageWidth:"20cm"}});

            • 3. Re: Where are withProperties arguments outlined?
              McShaman Level 1

              Thanks for your example

              It does not appear to be that putting too much in causes it to fail in your example... It just appears that the marginPreferences property is not accepted as a withProperty argument. Even the following does not work:

              app.documents.add({marginPreferences:{top:"10cm"}});

              From your example only the documentPreferences property works.

              Is this the only property that works? This is exactly my issue with the Adobe Scripting API. How am I meant to know without testing each one?

              • 4. Re: Where are withProperties arguments outlined?
                [Jongware] Most Valuable Participant

                Um, don't use the withProperties? As I said, you can totally work without them. It's not as if using them will lead to gigantic speed increases (it does, but only if *all* of your other code is already as fast and efficient as possible).

                • 5. Re: Where are withProperties arguments outlined?
                  McShaman Level 1

                  By using withProperties I am able to increase efficiancy within the script, reduce code and improve readability.

                   

                  Im sorry but my post was not for workarounds, I specificaly want to know about the withProperties arguments. If Adobe are going to provide an API they should properly document methods and arguments.

                  • 6. Re: Where are withProperties arguments outlined?
                    Trevorׅ Adobe Community Professional

                    I don't now what the problem with setting up a document "with properties"

                    One just have to properly understand the properties one is trying to set up.

                    Let's take Jongware example the "doesn't" work.

                     

                    app.documents.add({marginPreferences:{left:"0.5in", right:"0.5in", top:"24pt", bottom:"36pt"}, documentPreferences:{pageHeight:"10cm", pageWidth:"20cm"}});
                    

                     

                    Well it works great (I think)

                     

                    Here's the proof

                    Run it and see if you can keep the smiles of your faces.

                     

                     

                    app.activeDocument.layoutWindows[0].screenMode = ScreenModeOptions.PREVIEW_OFF;
                    doc = app.documents.add({documentPreferences:{pageHeight:"10cm", pageWidth:"20cm"}, marginPreferences:{left:"0.5in", right:"0.5in", top:"24pt", bottom:"36pt"}});
                    alert ("Document Margin Preferences\rLeft"+
                            doc.marginPreferences.left + "\rRight" + doc.marginPreferences.right
                            + "\rTop" +  doc.marginPreferences.top + "\rBottom" +  doc.marginPreferences.bottom)
                    doc.pages[0].marginPreferences.right= "3in";
                    alert ("Did you see that? we just changed the page margin Preference.");
                    doc.pages[0].marginPreferences.right= doc.marginPreferences.right;
                    alert ("Did you see that? we just changed the page margin Preference back to the document margin preference.");
                    

                     

                    Regards

                     

                    Trevor

                    • 7. Re: Where are withProperties arguments outlined?
                      Trevorׅ Adobe Community Professional

                      McShaman,

                       

                      Can you write some examples that realy don't work.

                      • 8. Re: Where are withProperties arguments outlined?
                        [Jongware] Most Valuable Participant

                        Trevor, my one-line Create Document / Set Size / Set Margin sets the correct document size but fails to pick up the new margins. I get the default margins I always get for a new document.

                         

                        Perhaps it's just because my preferred version to work with is CS4?

                        • 9. Re: Where are withProperties arguments outlined?
                          Trevorׅ Adobe Community Professional

                          Hi Jongware,

                           

                          The issue here is not document properties or cs5.

                          When you run your one line script you expect to see this note the smaller top margin.

                          _Untitled-142 @ 68%_2012-12-03_14-00-18.png

                          BUTthis is what you get.

                          _Untitled-142 @ 68%_2012-12-03_13-54-23.png

                          all the margins are the same.

                          BUT as stated this has nothing to do with the fact one is trying to do this in the set of the document with using your one liner

                           

                          app.documents.add({marginPreferences:{left:"0.5in", right:"0.5in", top:"24pt", bottom:"36pt"}})
                          

                           

                          or after the document is set up using my one liner

                           

                          app.activeDocument.marginPreferences.properties=({left:"0.5in", right:"0.5in", top:"24pt", bottom:"36pt"})
                          

                           

                          or the multiline

                           

                          app.activeDocument.marginPreferences.left = "0.5in";

                          app.activeDocument.marginPreferences.right = "0.5in";
                          app.activeDocument.marginPreferences.top = "24pt";
                          
                          app.activeDocument.marginPreferences.bottom = "36pt";
                          

                           

                          They all will do the same and the screen will still look line screenshot 2.

                           

                          BUT all these 3 methods HAVE set the document's margin preferences.

                           

                          To see this you have to set the PAGE margin preferences.

                          after running the above lines do this.

                           

                          app.activeDocument.pages[0].marginPreferences.top = app.activeDocument.marginPreferences.top; 
                          
                          
                          
                          
                          

                           

                          Then you'll see that the document setting were indeed set.

                           

                          To get the results you expected you needed to set the APPLICATION margin preferences.

                           

                          app.marginPreferences.properties=({left:"0.5in", right:"0.5in", top:"24pt", bottom:"36pt"})
                          

                           

                          now when you do

                          app.documents.add({documentPreferences:{pageHeight:"10cm", pageWidth:"20cm"}});

                           

                          You'll get the results shown in screen shot 1;

                           

                          In summary as far as I see (which is not very far) using with properties is not at all problematic, one just has to be clear on the properties of  WHAT one is trying to set.

                          I don't really see a lack in Adobe's documenting of this.

                           

                          Hope that's crystal clear and to everybody out there DON'T FORGET TO RESET YOUR APPLICATION  MARGIN PREFERENCES

                           

                          Regards

                           

                          Trevor

                          1 person found this helpful
                          • 10. Re: Where are withProperties arguments outlined?
                            McShaman Level 1

                            Thank you for clearing up marginPreferences Trevor. It was quite clear, however this dose not answer my original post. You have demonstrated that I can configure both the marginPreferences and documentPreferences through the withProperties argument... But what else? Where is the list of properties that can be configured through this argument at run time?

                             

                            I have looked at the document object  in the object model viewer and there are hundreds of properties. Am I assume they are all able to be configured with the withProperties argument?

                            • 11. Re: Where are withProperties arguments outlined?
                              Larry G. Schneider Adobe Community Professional & MVP

                              The short answer is yes. Most of the properties have defaults and if you don't explicitly set it to something it will use default.

                              • 12. Re: Where are withProperties arguments outlined?
                                Trevorׅ Adobe Community Professional

                                In a bit longer form than Larry put it.

                                 

                                I would guess the answer is that properties can all be set (except of id, index and that sort of read only stuff) but collection properties of collections cannot.

                                For example app.documents[0].rectangles

                                You can not set up a document and define the array of rectangles you want in it because to do that you would have to write app.documents.add({rectangles[0]:geometricBounds:[0,0,100,100]}})

                                The problem being the [0] this is because the key elements in the properties are keys which are strings and the string/key "rectangles[0]" is obviously not recognized.

                                 

                                Example 2 from Jongware

                                To make a pretty W in one line one uses (see http://forums.adobe.com/thread/1103517?tstart=0)

                                app.layoutWindows[0].activePage.ovals.add().paths[0].entirePath = [ [167,69],[147,123],[123,82],[100,125],[81,68],[72,72],[97,144],[123,98],[147,141],[176,73],[167,69] ];

                                For the above mentiond reason one cannot use

                                app.layoutWindows[0].activePage.ovals.add(paths[0]: {entirePath : [ [167,69],[147,123],[123,82],[100,125],[81,68],[72,72],[97,144],[123,98],[147,141],[176,73],[167,69] ]}});

                                 

                                So as a rule of thumb if its not a read only property like id, length or a collection property like rectangles then you can set it.

                                P.s. The above is all guess work but I think it's correct

                                I have looked at the document object  in the object model viewer and there are hundreds of properties.

                                 

                                Why on earth are you using the object model viewer and not Jongwares Object Model which is so much better?
                                Check out http://jongware.mit.edu/ for all the versions chm on windows is the best or http://jongware.mit.edu/idcs5js/

                                 

                                Trevor

                                • 13. Re: Where are withProperties arguments outlined?
                                  Trevorׅ Adobe Community Professional

                                  I hope you saw the edit that the can became can not (it was just a typo)

                                  • 14. Re: Where are withProperties arguments outlined?
                                    Harbs. Level 6

                                    If you check myObject.properties, that will return the available properties which can be set when the object is created using withProperties.

                                     

                                    Is that clear enough?

                                    • 15. Re: Where are withProperties arguments outlined?
                                      Trevorׅ Adobe Community Professional

                                      For example app.selection[0].properties.toSource()

                                      I made a script that reiterates through all the subcategories it can produce up to 160 pages of properties without getting into parent issues.