1 Reply Latest reply on Dec 10, 2014 10:04 PM by kenarli91

    JavaScript transfer indesign graphics from Illustrator

    kenarli91 Level 1

      hello;

      I want to write a code. The function of this code will be. I put avariable to each work in an Illustrator file. indesign javascript code with variables that make up the value entered in the dialog window, I want to help a command. Examples of thevariables that 5 of my illustrator file I think. I have written codeI would like the placement of 10 items found in the firstworksheet in the summer of 10 I 10 I want to be the firstvariable in the dialog box and illustrator file.

      The reason I want to use this code I'm stringing them one by one and really slow going. I succeed in writing this code you will earn a lot of time really



       


       


       


      I want to continue on this code



      var myDocument = app.activeDocument;


      myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;


      myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;


      var sekil = new Array;


      sekil = ["Kare", "Oval"]


      var myDialog = app.dialogs.add({name:"Sablon Olusturma", canCancel:true});


      with (myDialog){


          with (dialogColumns.add()){


              with (borderPanels.add()){


                  with(dialogColumns.add()){


                      staticTexts.add({staticLabel:"Kalip Eni :", minWidth:90});


                      staticTexts.add({staticLabel:"Kalip Boyu :", minWidth:90});


                  }


                  with (dialogColumns.add()){


                      var kalipEn = textEditboxes.add();


                      var kalipBoy = textEditboxes.add();


                  }


              }


              with(borderPanels.add()){


                  with (dialogColumns.add()){


                      staticTexts.add({staticLabel:"Ara Bosluk :", minWidth:90});


                  }


                  with (dialogColumns.add()){


                      var gutter = textEditboxes.add();


                  }


              }


              with(borderPanels.add()){


                  with (dialogColumns.add()){


                      staticTexts.add({staticLabel:"Tekli Eni :", minWidth:90});


                      staticTexts.add({staticLabel:"Tekli Boyu :", minWidth:90});


                  }


                  with (dialogColumns.add()){


                      var tekliEn = textEditboxes.add();


                      var tekliBoy = textEditboxes.add();


                  }


              }


              with (borderPanels.add()){


                  with (dialogColumns.add()){


                      staticTexts.add({staticLabel:"Cizim Sekli :", minWidth:90});


                      staticTexts.add({staticLabel:"Radius :", minWidth:90});


                  }


                  with(dialogColumns.add()){


                      var myDrop = dropdowns.add({stringList:sekil, selectedIndex:0});


                      var tRadius = textEditboxes.add();


                  }


              }


          }


      }


      var diaSonuc = myDialog.show();


      if (diaSonuc == true){


          var kEn = parseInt(kalipEn.editContents);


          var kBoy = parseInt(kalipBoy.editContents);


          var kgutter = gutter.editContents;


          if ((kgutter == null) || (kgutter == "")){


              kgutter = 0;


          } else {


              kgutter = parseInt(kgutter);


          }


          var tEn = parseInt(tekliEn.editContents);


          var tBoy = parseInt(tekliBoy.editContents);


          var myRadius = tRadius.editContents;


          if ((myRadius == null) || (myRadius == "")){


              myRadius = 0;


          } else {


              myRadius = parseInt(myRadius);


          }


          var yatay = Math.floor(kEn / (tEn+kgutter));


          var dikey = Math.floor(kBoy / (tBoy+kgutter));


          var genislik = (tEn * yatay) + (kgutter * (yatay - 1));


          var boy = (tBoy * dikey) + (kgutter * (dikey - 1));


          var startMarginLeft = (kEn - genislik) / 2;


          var startMarginTop = kBoy - (boy+10);


          if (startMarginLeft < 7){


              yatay = yatay -1;


              genislik = (tEn * yatay) + (kgutter * (yatay - 1));


              startMarginLeft = (kEn - genislik) / 2;


          }


          if (startMarginTop<10){


              dikey= dikey-1;


              boy = (tBoy * dikey) + (kgutter * (dikey - 1));


              startMarginTop = kBoy - (boy+10);


          }


          var sonuc = "Yatay :" + yatay + "  " + "Dikey :" + dikey + "\n Kaliptaki Etiket Sayisi :" + (yatay*dikey);


          alert(sonuc);


       


          var myLayer = myDocument.layers.item("Sablon");


          try{


              myLayerName = myLayer.name;


          }


          catch (myError){


              var myLayer = myDocument.layers.add({name:"Sablon"});


          }


          var myCutterColor = myDocument.colors.item("Bicak");


          try{


              myCutterColorName = myCutterColor.name;


          }


          catch(myError){


              var myCutterColor = myDocument.colors.add({name:"Bicak", model:ColorModel.process, colorValue:[0, 100, 100, 0]});


          }


          var myNoneSwatch = myDocument.swatches.item("None");


          var myRegistration = myDocument.colors.item("Registration");


          var myEtiket = new Array;


          var myCross1 = new Array;


          var myCross2 = new Array;


          var myCross3 = new Array;


          var myCross4 = new Array;


          var myCross5 = new Array;


          var myCross6 = new Array;


          var myCross7 = new Array;


          var myCross8 = new Array;


          if (myDrop.selectedIndex == 0){


              myEtiket[0] = myDocument.rectangles.add(myLayer, undefined, undefined, {strokeColor:myCutterColor, strokeWeight:0.25, fillColor:myNoneSwatch, geometricBounds:[startMarginTop, startMarginLeft, (tBoy+startMarginTop), (tEn+startMarginLeft)]});


              if (myRadius != 0){


                  myEtiket[0].cornerOption = CornerOptions.ROUNDED_CORNER;


                  myEtiket[0].cornerRadius =myRadius;          


              }


          }


          if (myDrop.selectedIndex == 1){


              myEtiket[0] = myDocument.ovals.add(myLayer, undefined, undefined, {strokeColor:myCutterColor, strokeWeight:0.25, fillColor:myNoneSwatch, geometricBounds:[startMarginTop, startMarginLeft, (tBoy+startMarginTop), (tEn+startMarginLeft)]});


          }


          myCross1[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[startMarginTop, (startMarginLeft-3), startMarginTop, (startMarginLeft-10)]});


          myCross2[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[(startMarginTop+tBoy), (startMarginLeft-3), (startMarginTop+tBoy), (startMarginLeft-10)]});


          myCross3[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[startMarginTop, (startMarginLeft+genislik+3), startMarginTop, (startMarginLeft+genislik+10)]});


          myCross4[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[(startMarginTop+tBoy), (startMarginLeft+genislik+3), (startMarginTop+tBoy), (startMarginLeft+genislik+10)]});


          myCross5[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[(startMarginTop-3), startMarginLeft, (startMarginTop-10), startMarginLeft]});


          myCross6[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[(startMarginTop-3), (startMarginLeft+tEn), (startMarginTop-10), (startMarginLeft+tEn)]});


          myCross7[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[(startMarginTop+boy+3), startMarginLeft, (startMarginTop+boy+10), startMarginLeft]});


          myCross8[0] = myDocument.graphicLines.add(myLayer,undefined, undefined,{strokeColor:myRegistration, strokeWeight:0.25, fillcolor:myNoneSwatch, geometricBounds:[(startMarginTop+boy+3), (startMarginLeft+tEn), (startMarginTop+boy+10), (startMarginLeft+tEn)]});


          var mmToPoint = 2.83464567


              for (var verti = 1; verti <= (dikey-1); verti++){


              var myVertDist = ((tBoy+kgutter)*verti)*mmToPoint;


              var myTransformationMatrix = app.transformationMatrices.add({verticalTranslation:myVertDist});


              myEtiket[verti] = myEtiket[0].duplicate();


              myCross1[verti] = myCross1[0].duplicate();


              myCross2[verti] = myCross2[0].duplicate();


              myCross3[verti] = myCross3[0].duplicate();


              myCross4[verti] = myCross4[0].duplicate();


              myEtiket[verti].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix);


              myCross1[verti].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix);


              myCross2[verti].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix);


              myCross3[verti].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix);


              myCross4[verti].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix);


          }


          for(var diz = 0; diz <= (dikey-1); diz++){


              for (var myCounter = 1; myCounter <= (yatay-1); myCounter++){


                  var myDistance = ((tEn + kgutter)*myCounter)*mmToPoint;


                  var myTransformationMatrix1 = app.transformationMatrices.add({horizontalTranslation:myDistance});


                  myEtiket[dikey+myCounter] = myEtiket[diz].duplicate();


                  myEtiket[dikey+myCounter].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix1);


              }          


          }


          for (var yanDiz = 1; yanDiz <= (yatay-1); yanDiz++){


              var myDistance = ((tEn + kgutter)*yanDiz)*mmToPoint;


              var myTransformationMatrix2 = app.transformationMatrices.add({horizontalTranslation:myDistance});


              myCross5[yatay+yanDiz] = myCross5[0].duplicate();


              myCross6[yatay+yanDiz] = myCross6[0].duplicate();


              myCross7[yatay+yanDiz] = myCross7[0].duplicate();


              myCross8[yatay+yanDiz] = myCross8[0].duplicate();          


              myCross5[yatay+yanDiz].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix2);


              myCross6[yatay+yanDiz].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix2);


              myCross7[yatay+yanDiz].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix2);


              myCross8[yatay+yanDiz].transform(CoordinateSpaces.pasteboardCoordinates, [[0,0], BoundingBoxLimits.geometricPathBounds], myTransformationMatrix2);


          }


          myDialog.destroy();


      }


       

        • 1. Re: JavaScript transfer indesign graphics from Illustrator
          kenarli91 Level 1


          var myGraphicFile = File.openDialog("Choose a graphic file");


          if((myGraphicFile != "")&&(myGraphicFile != null)){


          var myGraphic = myDocument.pages.item(0).place(myGraphicFile);


          myGraphic = myGraphic[0];


          var myObjectStyle = myDocument.objectStyles.item("GraphicFrame");


          try {


          var myName = myObjectStyle.name;


          }


          catch (myError){


          myObjectStyle = myDocument.objectStyles.add({name:"GraphicFrame"});


          }


          myObjectStyle.enableStroke = true;


          myObjectStyle.strokeWeight = 3;


          myObjectStyle.strokeType = myDocument.strokeStyles.item("Solid");


          myObjectStyle.strokeColor = myDocument.colors.item("Red");


          var myFrame = myGraphic.parent;


          myFrame.applyObjectStyle(myObjectStyle, true);


          myFrame.geometricBounds = [0,0,144,144];


          myFrame.fit(FitOptions.proportionally);


          myFrame.fit(FitOptions.frameToContent);


          var myBounds = myFrame.geometricBounds;


          var myGraphicWidth = myBounds[3]-myBounds[1];


          var myTopMargin = myDocument.pages.item(0).marginPreferences.top;


          myFrame.move([myPageWidth-myGraphicWidth, myTopMargin]);


          myFrame.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;


          myFrame.textWrapPreferences.textWrapOffset = [24, 12, 24, 12];


          }


           


           


          can you help in this work illustrator file with the abovecodes in ads pages I want to have my knees I want to transferto the variable indesign program, but the code does not work?I'm using CS6. Thanks to everyone