13 Replies Latest reply on Nov 14, 2011 7:24 AM by sotospeak (carlo bazzo)

    Printer Presets

    sotospeak (carlo bazzo)

      I have one script to output some documents to a postscript file.

       

      My UI shows a dropdown list with the printer presets:

       

      var printer_presets= app.printerPresets.everyItem().name;

      var preset_list = panel.add ("dropdownlist", undefined, printer_presets);

       

      From ID interface I can see two Printer Presets in my machine: one named "[Predefined]" and one "myPSpreset".

       

      Launching the script I can see my two presets in the dropdown list.

       

      My script needs then to set some options in the printer preset selected from the dropdown (mainly I want to set the output postscript file name) and I have:

       

      mypreset=app.printerPresets.item(myselected_preset_from_dropdown);

       

      Here comes the problem, if the preset named "myPSpreset" is selected from the dropdown, everything is ok I can read/write the object properties (mostly the property "printFile" ).

       

      But If the "[Predefined]" preset is selected from the dropdown I get mypreset=null and obviously tempting to read/write any property fails. The same happens in a different pc.

       

      What's the problem with [Predefined] preset? Thank you

        • 1. Re: Printer Presets
          கற்பனை (Imagine) Level 3

          required more details - ID ver, platform, scripting?

          • 2. Re: Printer Presets
            sotospeak (carlo bazzo) Level 1

            Sorry:

             

            Cs4-WIN-Javascript

            • 3. Re: Printer Presets
              கற்பனை (Imagine) Level 3

              Hi

               

              But If the "[Predefined]" preset is selected from the dropdown I get mypreset=null and obviously tempting to read/write any property fails. The same happens in a different pc.

              You've problem with getting the printer preset objects, from the selection dropdown box.  use the itemByName() method for preset objects.

               

              try this..

              • 4. Re: Printer Presets
                sotospeak (carlo bazzo) Level 1

                After some tests I think the "[Predefined]" printer preset can not be referenced by name ! Neither with item("name") or itemByName("name").

                Try this script:

                 

                mypreset=app.printerPresets.[0];

                $.write(mypreset.name);

                $.write(mypreset.printer);

                mypreset.printer=1886611052;

                $.write(mypreset.name);

                $.write(mypreset.printer);

                mypreset=app.printerPresets.[1];

                $.write(mypreset.name);

                $.write(mypreset.printer);

                 

                Output:

                 

                [Predefinito]

                Samsung ML-3050 Series

                [Predefinito]

                1886611052

                Predefinito di stampa 1

                1886611052

                Execution finished.

                 

                This is ok but now try this:

                 

                pr_name=app.printerPresets.[0].name;

                mypreset=app.printerPresets.itemByName(pr_name);

                $.write(mypreset.name);

                 

                Output:

                 

                Invalid Object

                 

                Anyone can confirm this?

                • 5. Re: Printer Presets
                  csm_phil Level 4

                  Hi Sotospeak,

                   

                  Can you please try the below JS code,  I feel you expect this.

                  This js code first get the all the printprests name after create the simple window and showin the drop down list in all the print preset name, whatever you select click ok it will shown the selected preset name.

                   

                   

                  var myPrint = app.printerPresets.everyItem().name;
                  var w = new Window ("dialog"); 
                  w.orientation = 'row';
                  var myDropDown = w.add ("statictext", undefined, "Print Preset Style Name"); 
                  var myDropDown = w.add ("dropdownlist", undefined, myPrint); 
                  myDropDown.selection = 0; 
                  var myButtonGroup =  w.add ("group"); 
                  myButtonGroup.add ("button", undefined, "OK"); 
                  w.center();
                  w.show();
                  alert(myDropDown.selection.text);
                  

                   

                   

                  thx

                  csm_phil

                  • 6. Re: Printer Presets
                    sotospeak (carlo bazzo) Level 1

                    thank you csm_phil for your time.

                     

                    The problem is not having the dropdown and selecting the preset names, I could accomplish that in a way similar to what you did.

                    The problem is you can NOT reference by name the Default printer preset ( "[Predefinito]" in the italian localized ID, I suppose something like "[Default]" in the english version).

                    I found eventually a way to get around this but I would like to get someone to acknowledge this sort of bug.

                     

                    Try this where the first lines are the same you showed:

                     

                    var myPrint = app.printerPresets.everyItem().name;
                    var w = new Window ("dialog");
                    w.orientation = 'row';
                    var myDropDown = w.add ("statictext", undefined, "Print Preset Style Name");
                    var myDropDown = w.add ("dropdownlist", undefined, myPrint);
                    myDropDown.selection = 0;
                    var myButtonGroup =  w.add ("group");
                    myButtonGroup.add ("button", undefined, "OK");
                    w.center();
                    w.show();
                    alert(myDropDown.selection.text);
                    //this is my addition
                    preset_name=myDropDown.selection.text;
                    mypreset=app.printerPresets.itemByName(preset_name);
                    alert(mypreset.name);

                     

                    When you choose the Default preset you have an error (mypreset is an invalid object, in fact it is null) but if you choose a user defined preset everything is ok.

                    • 7. Re: Printer Presets
                      John Hawkinson Level 5

                      It doesn't seem to work in English, where it is [Default]. I guess the workaround is to reference by index number...

                      1 person found this helpful
                      • 8. Re: Printer Presets
                        sotospeak (carlo bazzo) Level 1

                        Thank you John, so we can state this is a bug I suppose. And yes even my workaround was to reference to the Default  printer preset by index.

                         

                        Actually I used successfully app.printerPresets.[0] but I do not know if the zero index always points to the Deafult preset, can anyone confirm this? thank you

                        • 9. Re: Printer Presets
                          csm_phil Level 4

                          Hi Sotospeak,

                           

                          Where every you using [0] it connecting to the first index of the array. Can you please change the code like this app.printerPresets.[0] this to 'app.printerPresets[0]'.

                           

                          thx

                          csm_phil

                          • 10. Re: Printer Presets
                            sotospeak (carlo bazzo) Level 1

                            1- app.printerPresets is not an array.

                            2- my syntax is perfectly legal, see the docs

                            3- if you tried to suggest something I did not grasp it, sorry

                            • 11. Re: Printer Presets
                              John Hawkinson Level 5

                              Err, you guys do have me confused. I suppose it doesn't matter much, but:

                              1) app.printerPresets is not an Array, but it is a plural object, which is almost the same thing

                              2) app.printerPresets.[0] doesn't work for me, and it's pretty non-standard too. app.printerPresets[0] does. Did you mean to say app.printerPresets.item(0)?

                               

                              Not sure what documentation you were referring to...

                              • 12. Re: Printer Presets
                                csm_phil Level 4

                                Hi Soto,

                                 

                                what i am identifying your script, see the below error in your script. John, understand my corrections of the script thanks john.

                                 

                                'app.printerPresets.[0]'

                                 

                                instead of this

                                 

                                app.printerPresets[0];

                                 

                                thx

                                csm_phil

                                • 13. Re: Printer Presets
                                  sotospeak (carlo bazzo) Level 1

                                  mmmh very strange. This script is perfectly working in win CS4 and every statement looks equivalent :

                                   

                                  pr_name=app.printerPresets.[0].name;

                                  $.write(pr_name);

                                  pr_name=app.printerPresets[0].name;

                                  $.write(pr_name);

                                  pr_name=app.printerPresets.item(0).name;

                                  $.write(pr_name);

                                   

                                  Regarding the docs I was referring to, I get this from ESTK Object Model Viewer (notice the dot before square brackets ):

                                   

                                  PrinterPresets.[] (index: number ): PrinterPreset

                                  Adobe InDesign CS4 (6.0) Object Model Object Model

                                  Returns the PrinterPreset with the specified index.

                                  index: Data Type: number

                                  The index.

                                   

                                  ***EDIT***

                                  I see in CS5.5 that the .[index]  notation does not work anymore but I confirm in CS4 it does.

                                   

                                  Message was edited by: sotospeak (carlo bazzo)