Search code examples
javascriptadobe-illustratorextendscript

Return the dimensions of a place image in extendscript


I have an illustrator file that contains a placed image which is contained within a clipping path of similar size, not exactly but only a couple of pixels out. When I click on the image in illustrator and look at the info box it has a width of 122, height 142, x of 4 and a y of 31. But hen I console out its attributes the heigh and width correspond, but I cannot work out how to access the correct y coordinate. The x is correct by the y return a value of 615. Any ideas where I’m going wrong?

$.writeln(
          "item width ",
          item.width,
          " item height ",
          plotAttributes.height,
          " item x ",
          item.position[0],
          " item y ",
          item.position[1]
        );

This is the output from that code

item width 122.217691478349 item height 140.24222158557 item x 4.94846351403703 item y 615.716058690518


Solution

  • Hmm I think its the coordinates system. If i set it to a relative system

    app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

    Then make sure that the rule origin in the top left corner is at [0,0] It seem to work

    doc.artboards[0].rulerOrigin = [0, 0];