1 Reply Latest reply on Jun 3, 2014 1:00 PM by Jump_Over

    Javascript version Problem

    JonnyDL Level 1

      Ive written Javascript on my laptop which uses Indesign CS 5.5, I run the code and it works (no errors, still fine tuning it), but when I try and run it on my work computer (mac) running Indesign 5 I get an error

      "Invalid Parameter". Are there differences in the syntax between these to versions?

      Here is the/a line of code that causes the error (i have this code several times creating boxes.)

       

      myrectanglesplitterleft= rectangles.add({geometricBounds:[(.75+bleeddepth), 0, (myPageHeight/3)+(.75+bleeddepth), bleeddepth],fillColor:"Proofyellow"});

       

      Here is the whole thing if it might be something else related to this error that isn't being passed improperly between one version (5.5) and not the other (5)

      hopefully someone can help

       

      #target "InDesign"

       

       

      ///global variables

      var myChoice = "Cancel"

      var magBleedDepth = .5;

      var bookBleedDepth = .25;

      var halfbookBleedDepth = .25;

      var redopacity = 45;

      var yellowopacity = 55;

      var myPath =  Folder.desktop;

       

       

      var myDoc = app.documents[0];

      var fileNameWextn= myDoc.name;

      var fileNameArray = fileNameWextn.split(".");

      var fileName = fileNameArray[0]

       

       

      ////holds old doc settings to return them after pdf is made////

      var myOldXUnits = myDoc.viewPreferences.horizontalMeasurementUnits;

      var myOldYUnits = myDoc.viewPreferences.verticalMeasurementUnits;

      var myOldGuides = myDoc.guidePreferences.guidesShown;

       

       

      ////main function -- sets doc prefs, and builds dialog box

      function guideSize ()

      {

          var pubtype = "Unknown"

          var myPageWidth = myDoc.documentPreferences.pageWidth;

          var myPageHeight= myDoc.documentPreferences.pageHeight;

        

          //////Magazine--------------------------------------------------------------------------- -----------

          // FullPage (bleed) 8.625”x11.375”

          if (myPageWidth == 8.625 && myPageHeight == 11.375)

              {

                     var pubtype = "Magazine"

                     var bleeddepth = magBleedDepth

              }

       

          // 2-Page Spread (bleed) 16.75”x11.375”

          if (myPageWidth == 16.75 && myPageHeight == 11.375)

              {

                     var pubtype = "Magazine"

                     var bleeddepth = magBleedDepth

              }

       

          // 1/2Page (top bleed horizontal) 8.625” x 5.4375”

            if (myPageWidth == 8.625 && myPageHeight == 5.4375)

              {

                    var pubtype = "Magazine"

                    var bleeddepth = magBleedDepth

              }

       

          // 1/2Page (bottom bleed horizontal) 8.625”x 5.6875”

             if (myPageWidth == 8.625 && myPageHeight == 5.6875)

              {

                   var pubtype = "Magazine"

                   var bleeddepth = magBleedDepth

              }

         //////Magazine--------------------------------------------------------------------------- -----------

         

         ////////Book

          // 2-Page Spread (bleed) 11.25" x 8.75"

          if (myPageWidth == 11.25 && myPageHeight == 8.75)

              {

                   var pubtype = "Half Book"

                   var bleeddepth = halfbookBleedDepth

              }

       

          // Full Page (bleed) 6" x 9"

              if (myPageWidth == 6 && myPageHeight == 9)

              {

                   var pubtype = "Half Book"

                   var bleeddepth = halfbookBleedDepth

              }

         

          //Book

              if (myPageWidth == 8.75 && myPageHeight == 11.25)

              {

                   var pubtype = "Book"

                   var bleeddepth = bookBleedDepth

              }

         

                  if (myPageWidth == 17 && myPageHeight == 11.25)

              {

                   var pubtype = "Book"

                   var bleeddepth = bookBleedDepth

              }

       

      }

       

       

       

       

       

       

      ////sets some prefs and builds dialog

      function myDialog(myPageWidth, myPageHeight, pubtype, bleeddepth)

      {

          with (myDoc.viewPreferences)

          {

            horizontalMeasurementUnits = MeasurementUnits.inches;

            verticalMeasurementUnits = MeasurementUnits.inches;

            }

       

          with(app.pdfExportPreferences)

          {

              exportGuidesAndGrids = false;

              exportLayers = false;

              exportNonPrintingObjects = false;

       

       

            }

       

          with(myDoc.guidePreferences)

          {

              guidesShown= true;

              guidesLocked = false;

            }

       

          /////////////////////////////////////////////////////////////////set Dialog window for choice of guides or bleed markers

              var bleedDialog=new Window("dialog", "Check The Bleed");

              var infopanel = bleedDialog.infoPnl = bleedDialog.add("panel", undefined, "Document Info");

              var infoGroup = bleedDialog.infoPnl.add ("group");

              var radioGroup = bleedDialog.add ("group");

              var choiceGroup = bleedDialog.add ("group");

       

       

              bleedDialog.orientation="row"

       

       

              var docname = infoGroup.add("statictext", undefined, "Doc Name:     "+ fileName);

              var type = infoGroup.add("statictext", undefined, "Pub Type:       "+ pubtype);

              var docwidth = infoGroup.add("statictext", undefined, "Width:            "+ myPageWidth +'"');

              var docheight = infoGroup.add("statictext", undefined, "Height:          "+ myPageHeight +'"');

              var bleedArea = infoGroup.add("statictext", undefined, "Bleed area: "+ bleeddepth );

       

       

              infopanel.margins=[10,20,10,20]

              docname.alignment = "left";

              type.alignment = "left";

              docwidth.alignment = "left";

              docheight.alignment = "left";

              with (infoGroup)

              {

               infoGroup.orientation = "column";

               infoGroup.spacing ="6";

              }

       

       

       

       

              var justGuides = radioGroup.add("radiobutton", undefined, "Guides");

              var justMarkers = radioGroup.add("radiobutton", undefined, "Bleed Fills");

              with (radioGroup)

              {

               radioGroup.orientation = "column";

               radioGroup.spacing ="10";

                justGuides.alignment = "left"

                justMarkers.alignment = "left"

                justMarkers.spacing = "5";

              }

       

       

              justGuides.value = true;

              var okbtn = radioGroup.add("button", undefined, "Set")

              var stopbtn = radioGroup.add("button", undefined, "Nope")

             

              if (pubtype == "Unknown")

                  {

                      okbtn.enabled = false

                      alert("Document does not match bleed size")

                   }

       

       

              okbtn.onClick =function ()

                  {

                  bleedDialog.close();

                  if(justGuides.value==true)

                  {

                      myChoice = "guides"

                  

                   }

                  else

                  {

                      myChoice = "markers"

                   }

                  }

       

       

              stopbtn.onClick =function (){bleedDialog.close()}

       

       

              if (bleedDialog.show()!=true){

                  if ( myChoice == "guides"){guides (myPageWidth, myPageHeight, pubtype, bleeddepth)}

                  if ( myChoice == "markers"){markers (myPageWidth, myPageHeight, pubtype, bleeddepth)}

                  if ( myChoice == "Cancel"){bleedDialog.close(); }

                  }  

      }

       

       

       

       

      ///Creates Guides

      function guides(myPageWidth, myPageHeight, pubtype, bleeddepth)

      {

          try

              {

              var myLayer = myDoc.layers.item("Bleed Guides").name;

              }

          catch (myError)

              {

              var myLayer = myDoc.layers.add({name:"Bleed Guides"});

              }

         

          with(myDoc.pages.item(0))

                      {

                      var myLayer = app.documents.item(0).layers.item("Bleed Guides");

                      guides.add(myLayer, {orientation:HorizontalOrVertical.vertical, location:(myPageWidth-bleeddepth)});

                      guides.add(myLayer, {orientation:HorizontalOrVertical.vertical, location:(bleeddepth)});

                      guides.add(myLayer, {orientation:HorizontalOrVertical.horizontal, location:(myPageHeight-bleeddepth)});

                      guides.add(myLayer, {orientation:HorizontalOrVertical.horizontal, location:(bleeddepth)});

                      }

           

          with(app.pdfExportPreferences)

              {

                  exportGuidesAndGrids = true;

                  exportLayers = true;

                  exportNonPrintingObjects = false;

       

       

                }

           

             ///export PDF

             myDoc.exportFile(ExportFormat.pdfType, new File(myPath+"/"+fileName+"_Bleed Proof.pdf"), false);

           

            ///set prefs just to be extra cautious

          with(app.pdfExportPreferences)

              {

                  exportGuidesAndGrids = false;

                  exportLayers = false;

                  exportNonPrintingObjects = false;

       

       

                }

            

             ////Remove layer

             var bleedLayer = myDoc.layers.item("Bleed Guides")

             bleedLayer.remove();

            

             ///run restore

             restorePrefences()

                 

            alert ('Make Sure the Layer "Bleed Guides" is deleted before you send back the Document');

      }

       

       

       

       

      ///Creats Markers

      function markers(myPageWidth, myPageHeight, pubtype, bleeddepth)

      {

          try

              {

              var myLayer = myDoc.layers.item("Bleed Guides").name;

              }

          catch (myError)

              {

              var myLayer = myDoc.layers.add({name:"Bleed Guides"});

              }

         

          with(myDoc.pages.item(0))

                      {

                      var myLayer = app.documents.item(0).layers.item("Bleed Guides");

                      myrectangletop = rectangles.add({geometricBounds:[0, 0, 100, 100],fillColor:"ProofRed"});

                      myrectangletop.transparencySettings.blendingSettings.opacity = redopacity;

                      myrectangletop.strokeWeight = 0;

                     

                      myrectanglesplittertop = rectangles.add({geometricBounds:[0, bleeddepth+.75, bleeddepth, (myPageWidth/3)+(.75+bleeddepth)],fillColor:"Proofyellow"});

                      myrectanglesplittertop.transparencySettings.blendingSettings.opacity = yellowopacity;

                      myrectanglesplittertop.strokeWeight = 0;

                      ///////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////

                    

                      myrectangleleft = rectangles.add({geometricBounds:[0, 0, myPageHeight, bleeddepth],fillColor:"ProofRed"});

                      myrectangleleft.transparencySettings.blendingSettings.opacity = redopacity;

                      myrectangleleft.strokeWeight = 0;

                     

                      myrectanglesplitterleft= rectangles.add({geometricBounds:[(.75+bleeddepth), 0, (myPageHeight/3)+(.75+bleeddepth), bleeddepth],fillColor:"Proofyellow"});

                      myrectanglesplitterleft.transparencySettings.blendingSettings.opacity = yellowopacity;

                      myrectanglesplitterleft.strokeWeight = 0;

                      ///////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////

                     

                      myrectanglelright= rectangles.add({geometricBounds:[0, myPageWidth-bleeddepth, myPageHeight, myPageWidth],fillColor:"ProofRed"});

                      myrectanglelright.transparencySettings.blendingSettings.opacity = redopacity;

                      myrectanglelright.strokeWeight = 0;

                     

                      myrectanglesplitterright= rectangles.add({geometricBounds:[myPageHeight-((myPageHeight/3)+(bleeddepth+.75)), myPageWidth-bleeddepth, myPageHeight-(bleeddepth+.75), myPageWidth],fillColor:"Proofyellow"});

                      myrectanglesplitterright.transparencySettings.blendingSettings.opacity = yellowopacity;

                      myrectanglesplitterright.strokeWeight = 0;

                      ///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////

                     

                      myrectanglebottom = rectangles.add({geometricBounds:[myPageHeight-bleeddepth, bleeddepth, myPageHeight, myPageWidth-bleeddepth],fillColor:"ProofRed"});

                      myrectanglebottom.transparencySettings.blendingSettings.opacity = redopacity;

                      myrectanglebottom.strokeWeight = 0;

                     

                      myrectanglesplitterbottom = rectangles.add({geometricBounds:[myPageHeight-bleeddepth, myPageWidth-((myPageWidth/3)+.75+bleeddepth), myPageHeight, myPageWidth-(bleeddepth+.75)],fillColor:"Proofyellow"});

                      myrectanglesplitterbottom.transparencySettings.blendingSettings.opacity = yellowopacity;

                      myrectanglesplitterbottom.strokeWeight = 0;

                      }

           

          with(app.pdfExportPreferences)

              {

                  exportGuidesAndGrids = true;

                  exportLayers = true;

                  exportNonPrintingObjects = false;

       

       

                }

           

             ///export PDF

             myDoc.exportFile(ExportFormat.pdfType, new File(myPath+"/"+fileName+"_Bleed Proof.pdf"), false);

           

            ///set prefs just to be extra cautious

          with(app.pdfExportPreferences)

              {

                  exportGuidesAndGrids = false;

                  exportLayers = false;

                  exportNonPrintingObjects = false;

       

       

                }

            

             ////Remove layer

             var bleedLayer = myDoc.layers.item("Bleed Guides")

             bleedLayer.remove();

            

             ///run restore

             restorePrefences()

                 

            alert ('Make Sure the Layer "Bleed Guides" is deleted before you send back the Document');

      }

       

       

       

      ///////restoring user prerences, setting exports back to norm

      function restorePrefences ()

      {

              with (myDoc.viewPreferences)

          {

            horizontalMeasurementUnits = myOldXUnits;

            verticalMeasurementUnits = myOldYUnits;

            }

       

          with(app.pdfExportPreferences)

          {

              exportGuidesAndGrids = false;

              exportLayers = false;

              exportNonPrintingObjects = false;

       

       

            }

       

          with(myDoc.guidePreferences)

          {

              guidesShown= myOldGuides;

              guidesLocked = false;

            }

        }

       

       

      guideSize()