1 Reply Latest reply on Jul 2, 2014 7:39 AM by CarlosCanto

    How to replace a text frame by a .ai file?

    KevinLecocq Level 1

      Hi,

      I am writing an javascript Illustrator script opening an AI file, getting a text frame in the layers/pageItems by its content, then replacing it by a placedItem embedding another .ai file (a little shape).

      I managed to get the pageItem and to create the placedItem in this way:

       

      ...
      var item = mainGroupElement.pageItems[i];
      if(item.contents == 'X') {
        $.write("X found\n");
      
        var walkingManFile = File("D:\\walking-man.ai");
        var walkingManItem = mainGroupElement.placedItems.add();
        walkingManItem.file = walkingManFile;
        walkingManItem.embed();
        var scaleX = item.width / walkingManItem.width * 100;
        var scaleY = item.height / walkingManItem.height * 100;
        walkingManItem.resize(scaleX, scaleY, true, false, false, false, 100, Transformation.CENTER);
        var deltaX = item.position[0] - walkingManItem.position[0];
        var deltaY = item.position[1] - walkingManItem.position[1];
        walkingManItem.translate(deltaX, deltaY, true, false, false, false);
        walkingManItem.trace();
      
        item.remove();
      }
      
      

       

      'item' typename is TextFrame.

      The shape "walkingMan" is well traced, but not translated and resized at all. However, the scaleX, scaleY, deltaX and deltaY values seem good.

      Does anyone know what I'm doing wrong here?

      I would appreciate any help on it!