4 Replies Latest reply on May 12, 2015 3:13 AM by Sketch_Ak

    Create a new document in mm not pt

    Sketch_Ak

      Hi there,

       

      Total newbie here to the world of scripting.

      Problem with below code in terms of size, it has pt as the input but I want it in mm.

      I've kind of got it working as is but the dialogue box still says pt and not mm even though it ends up correct?

       

      Thanks for your help in advance.

       

          var myDialog = app.dialogs.add({name:"Hems Only V1",canCancel:true});

          with(myDialog){

        //ADD DIALOG COLUMN.

        with(dialogColumns.add()){

               staticTexts.add({staticLabel:"NOTE: Document will be in mm, ignore pt"});

                      //CREATE BOARDER PANEL

                      with(borderPanels.add()){

                      with(dialogColumns.add()){

                      //LABEL WIDTH.

                     staticTexts.add({staticLabel:"Width:"});

                      with(dialogColumns.add()){

                      //ENTER WIDTH.

                      var myPageWidthField = measurementEditboxes.add({editValue:50});

                      }

                      //LABEL HEIGHT.

                      with(dialogColumns.add()){

                      staticTexts.add({staticLabel:"Height:"});

                      //ENTER WIDTH.

                      with(dialogColumns.add()){

                      var myPageHeightField = measurementEditboxes.add({editValue:50});          

                      }

                      }

                      }

                      }

              }

       

       

              //DISPLAY DIALOG BOX.

              var myResult = myDialog.show();

              if(myResult == true){

                 

              //GET VALUES FROM DIALOG BOX CONTROLS.

              var myString2 = myPageWidthField.editValue ;

              var myString3 = myPageHeightField.editValue;

             

              //REMOVE DIALOG BOX FROM MEMORY.

              myDialog.destroy();

              myMakeDocument(myString2, myString3);

              }

              else{

              myDialog.destroy();

              }

              }

       

       

              function myMakeDocument(myString2, myString3){

              //CREATE NEW DOCUMENT.

              var myDocument = app.documents.add()

              with(myDocument.documentPreferences){

       

       

              //BLEED SETTINGS

              documentBleedBottomOffset = "4";

              documentBleedTopOffset = "4";

              documentBleedInsideOrLeftOffset = "4";

              documentBleedOutsideOrRightOffset = "4";

              //SLUG SETTINGS

              slugBottomOffset = "0";

              slugTopOffset = "0";

              slugInsideOrLeftOffset = "0";

              slugRightOrOutsideOffset = "0";

              //FACING PAGES SETTING

              facingPages = false;

              }

       

       

              //MEASUREMENT UNITS AND RULER ORIGIN SETTING.

              myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;

              myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;

              myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

       

       

              //SET DOCUMENT SIZE USING VALUES SET IN DIALOG BOX.

              myDocument.documentPreferences.pageWidth = myString2;  

              myDocument.documentPreferences.pageHeight = myString3;  

       

       

              //Get a reference to the first master spread.

              var myMasterSpread = myDocument.masterSpreads.item(0);

              //Get a reference to the margin preferences of the first page in the master spread.

              var myMarginPreferences = myMasterSpread.pages.item(0).marginPreferences;

       

       

              //SET MARGINS AND COLUMNS.

              myMarginPreferences.left = 0;

              myMarginPreferences.top = 0;

              myMarginPreferences.right = 0;

              myMarginPreferences.bottom = 0;

              myMarginPreferences.columnCount = 1;

              myMarginPreferences.columnGutter = 4;

       

       

              //PAGE ITEMS KEYLINE AND EMPTY TEXT BOX FOR CREATIVE LINK

              var myDocument = app.documents.item(0);

              var myPage = myDocument.pages.item(0);

              //Given a page "myPage", KEYLINE RECTANGLE.

              var myRectangle = myPage.rectangles.add({geometricBounds:[myString3 + 4, myString2 + 4, -4, -4]});

              //Given a page "myPage", TEXT BOX FOR CREATIVE LINK.

              var myTextFrame = myPage.textFrames.add({geometricBounds:[myString3, myString2, 0, 0]});

          }