Skip to main content
maryg56488698
Participant
February 28, 2019
Question

jsx script not working as it is in regular script illustrator cc 2019

  • February 28, 2019
  • 1 reply
  • 991 views

I'm using illustrator cc 2019

I currently have a script that's evaluating a script from cep to jsx.

var csi = new CSInterface();

var retString = 'blah'

csi.evalScript("platePlacement(" + retString + ")")

This runs the method platePlacement located in my jsx.  Full code is this:

function platePlacement(plateData) {

    alert('blah blah');

    // open the template

    var f = new File("/Users/Desktop/test.ai");

    var doc = app.open (f);

    // here we set color of text

    var col = new RGBColor();

    col.red = 255;

    col.green = 0;

    col.blue = 0;

    // activate current document

    var aDoc = app.activeDocument;

    // aDoc.rulerOrigin = [0, 0];

    // aDoc.pageOrigin = [0, 0];

    var bkgrndPlate = new File("/Users/Desktop/test2.ai");

    var placeFiles = aDoc.placedItems.add();

    // place linked file on document

    placementMeasurements = {top1: -4.5, left1: 4.8};

    placeFiles.file = bkgrndPlate;

    placeFiles.top = placementMeasurements.top1;

    placeFiles.left = placementMeasurements.left1;

    // placeFiles.position = [4.863, 50];

    // place text on document

    var text = aDoc.textFrames.add();

    text.textRange.size = 49;

    text.textRange.characterAttributes.fillColor = col;

    text.textRange.characterAttributes.horizontalScale = 80;

    text.contents = "blah blah";

    text.textRange.characterAttributes.textFont = textFonts.getByName("Helvetica");

    text.textRange.justification = Justification.CENTER;

    // calcuate left side placement of text

    var textWidth = text.width;

    var plateWidth = 288;

    text.top = -43.4;

    text.left = calculateLeftPlacement(textWidth, plateWidth);

    function calculateLeftPlacement(textWidth, plateWidth) {

      var widthCalculation = ((plateWidth - textWidth) / 2) + 4.8;

      return widthCalculation;

    }

}

The program skips the alert, then loads the file test2.ai and that's all.  There are no errors, it just stops executing.  When I run this exact script from Scripts in illustrator cc it works perfect.  What am I missing here?

This topic has been closed for replies.

1 reply

Participant
April 4, 2019

I don't see anything wrong with this. You should see alert popping up. I just confirmed it works in AI 2019. Could you share your extension via Github or something? I can take a look.. Here is what I have on my end:

JS:

var csInterface = new CSInterface();

var opendocButton = document.querySelector("#opendoc-button");

opendocButton.addEventListener("click", openDoc);

function openDoc() {

    csInterface.evalScript("openDoc()", function (data) {

        console.log(data)

    });

    csInterface.resizeContent(100, 250)

}

JSX:

function openDoc() {

   if (app.name == "Adobe Illustrator") {

   alert("hello")

   var fileRef = new File("~/Downloads/aiexample.jpg")

   var docRef = app.open(fileRef)

  } else if (app.name == "Adobe Photoshop") {

   var fileRef = new File("~/Downloads/psexample.jpg")

   var docRef = app.open(fileRef)

  } else if (app.name == "Adobe InDesign") {

   var fileRef = new File("~/Downloads/idexample.indd")

   var docRef = app.open(fileRef)

  }

}