Scale with Anchor Position in UXP?

In the UXP DOM, it seems that the new scale feature only supports centered scaling, and not anchor positions. Is that correct? Or is there something not documented yet that can allow anchor positions? Doing through batchPlay would be a pain because it calculates a center movement and scale percentage. So you would need to first make a selection, get the bounds, and then calculate the center movement any time you want to scale anchored. I’m really hoping there is an easier way to do this.

This is the old JSX API that I am tryign to do in UXP.

app.activeDocument.activeLayer.resize( 30, 30, AnchorPosition.TOPLEFT );

This is the new API in UXP… but nothing in the docs mention Anchor positioning. I tried to add the anchor position the same way as the old API but it didn’t scale anything that way. With it like this, it always scales centered.

await app.activeDocument.activeLayers[0].scale(30,30);

Here is the descriptor from Alchemist. As mentioned, if getting the selection bounds first, calculations could then be made to make this work with the vertical and horizontal offsets. However, that seems really cumbersome to be doing the anchored scaling.

{
   "_obj": "transform",
   "_target": [
      {
         "_ref": "layer",
         "_enum": "ordinal",
         "_value": "targetEnum"
      }
   ],
   "freeTransformCenterState": {
      "_enum": "quadCenterState",
      "_value": "QCSAverage"
   },
   "offset": {
      "_obj": "offset",
      "horizontal": {
         "_unit": "pixelsUnit",
         "_value": -161.43151468090673
      },
      "vertical": {
         "_unit": "pixelsUnit",
         "_value": -262.00570565082256
      }
   },
   "width": {
      "_unit": "percentUnit",
      "_value": 30
   },
   "height": {
      "_unit": "percentUnit",
      "_value": 30
   },
   "linked": true,
   "interfaceIconFrameDimmed": {
      "_enum": "interpolationType",
      "_value": "bicubicAutomatic"
   },
   "_isCommand": true
}

OK, I figured it out. Instead of using the corner handle when doing the transform, you need to enable the anchor positioning in the tool options. Then it will record as needed in Alchemist. It then keeps the offsets at zero and changes the freeTransformCenterState to the corner you choose. Much easier now :slight_smile:

{
   "_obj": "transform",
   "_target": [
      {
         "_ref": "layer",
         "_enum": "ordinal",
         "_value": "targetEnum"
      }
   ],
   "freeTransformCenterState": {
      "_enum": "quadCenterState",
      "_value": "QCSCorner0"
   },
   "offset": {
      "_obj": "offset",
      "horizontal": {
         "_unit": "pixelsUnit",
         "_value": 0
      },
      "vertical": {
         "_unit": "pixelsUnit",
         "_value": 0
      }
   },
   "width": {
      "_unit": "percentUnit",
      "_value": 30
   },
   "height": {
      "_unit": "percentUnit",
      "_value": 30
   },
   "linked": true,
   "interfaceIconFrameDimmed": {
      "_enum": "interpolationType",
      "_value": "bicubicAutomatic"
   },
   "_isCommand": true
}