# Place (linked) with original with and height

**URL:** <https://forums.creativeclouddeveloper.com/t/place-linked-with-original-with-and-height/3983>\
**Category:** UXP Plugin API\
**Created:** [December 5, 2021, 12:42am UTC](https://forums.creativeclouddeveloper.com/t/place-linked-with-original-with-and-height/3983 "2021-12-05T00:42:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrPepperJo](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@DrPepperJo](https://forums.creativeclouddeveloper.com/u/DrPepperJo)\
**Post date:** [December 5, 2021, 12:42am UTC](https://forums.creativeclouddeveloper.com/t/place-linked-with-original-with-and-height/3983/1 "2021-12-05T00:42:52Z")

</div>

When placing image files (jpg and raw) into a document using batch play, I want them to retain their original width and height in pixels and start at the top left of the canvas. Unfortunately, I did not find a documentation for the parameters of the batch play command, and have a number of questions:

1. When I place raw files, the batch play command automatically uses the resolution set in `Camera Raw Preferences / Image Sizing / Resolution`. However, I would like to use the resolution of the document. Is there a way to include this request in the script?

1. When recording the placement with Alchemist, the `Set horizontal/vertical scale` setting leads to the introduction of the the `width` and `height` parameters below. However the percentage value is not 100%, but an upscale from the image scaled to fit the canvas. Setting `unit` to `pixelsUnit` does not work for me either, it seems to still interpret the value as a percentage. Is there a way to avoid this scaling to canvas in the first place or an easy way to set the `width` and `height` parameters without additional calculations?

2. Changing the `Set horizontal/vertical position of the reference point` to 0 results in a similarly “precalculated” value that shifts the center to upper left corner. Only after the placement, changing the `Transform` settings of the `Linked Smart Object` to 0px does the trick. However, the batch play `move` operation defines the position not in canvas coordinates but as an offset to the current position of the layer image. Again, is there a way to directly set the origin of the layer image to the top left corner of the canvas? If not, is there a a way to provide a canvas position instead of an offset to the batch play `move` command?

1. Is there a documentation for the batch play commands somewhere?

> ```
> const result = await batchPlay(
> [
> {
> _obj: "placeEvent",
> ID: 5,
> null: {
> _path: token,
> _kind: "local"
> },
> linked: true,
> openAs: {},
> freeTransformCenterState: {
> _enum: "quadCenterState",
> _value: "QCSAverage"
> },
> offset: {
> _obj: "offset",
> horizontal: {
> _unit: "pixelsUnit",
> _value: [some value]
> },
> vertical: {
> _unit: "pixelsUnit",
> _value: [some value]
> }
> },
> width: {
> _unit: "percentUnit",
> _value: [usually some value != 100]
> },
> height: {
> _unit: "percentUnit",
> _value: [usually some value != 100]
> },
> _options: {
> dialogOptions: "dontDisplay"
> }
> }
> ], {}
> );
> 
> ```

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [December 5, 2021, 2:05pm UTC](https://forums.creativeclouddeveloper.com/t/place-linked-with-original-with-and-height/3983/2 "2021-12-05T14:05:25Z")

</div>

> [@DrPepperJo](#):
>
> When recording the placement with Alchemist, the `Set horizontal/vertical scale` setting leads to the introduction of the the `width` and `height` parameters below. However the percentage value is not 100%, but an upscale from the image scaled to fit the canvas. Setting `unit` to `pixelsUnit` does not work for me either, it seems to still interpret the value as a percentage. Is there a way to avoid this scaling to canvas in the first place or an easy way to set the `width` and `height` parameters without additional calculations?

In general, Photoshop does only do scaling of places images when the placed image is larger than the available space. This can be turned off in the settings:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/a/aed6b86bf1e3d8e9c54de92f5c96b9944f70d8a8.png)  
However, there’s another edge case where Photoshop does some scaling: When the resolution (ppi) of the document and the placed image doesn’t match. I don’t know if there’s a way to avoid that, otherwise you could adjust the image resolution before placing (given, that you know the resolution of the placed image).

> [@DrPepperJo](#):
>
> Changing the `Set horizontal/vertical position of the reference point` to 0 results in a similarly “precalculated” value that shifts the center to upper left corner. Only after the placement, changing the `Transform` settings of the `Linked Smart Object` to 0px does the trick. However, the batch play `move` operation defines the position not in canvas coordinates but as an offset to the current position of the layer image. Again, is there a way to directly set the origin of the layer image to the top left corner of the canvas? If not, is there a a way to provide a canvas position instead of an offset to the batch play `move` command?

Move (or transform in general) always works as a change on top of the current state. So it isn’t really possible to directly specify an absolute position or final coordinates. I also think it isn’t the greatest design decision, but to be honest the math to get the desired result isn’t the hardest one either. Even the UI inputs where you can set an absolute position will result in a relative move, if you record the respective BatchPlay code. Just subtract the current position from the target position and you get the necessary movement vector.

There are however two ways to (kind of) set the position directly:

1. Use the alignment buttons
2. For shape layers, I think it’s possible to adjust the rectangle that defines the shapes position and size directly.

> [@DrPepperJo](#):
>
> Is there a documentation for the batch play commands somewhere?

Nope. Just record with Alchemist, do it again while changing tool settings etc. and evaluate the changes. Most descriptors keys are also self-explanatory.

---

<div class="post-metadata">

**Author:** ![DrPepperJo](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@DrPepperJo](https://forums.creativeclouddeveloper.com/u/DrPepperJo)\
**Post date:** [November 21, 2022, 1:39am UTC](https://forums.creativeclouddeveloper.com/t/place-linked-with-original-with-and-height/3983/3 "2022-11-21T01:39:06Z")

</div>

So, I’ve decided to go with a very generic solution by placing a linked file regardless of ppi and resize option and then translating and scaling it into place as follows:

```auto
  layer = ps.app.activeDocument.activeLayers[0]; 
  await layer.translate( -layer.bounds.left, -layer.bounds.top );
  await layer.scale( 100 * width / layer.bounds.right, 100 * height / layer.bounds.bottom, consts.AnchorPosition.TOPLEFT );

```

I guess the scale factor will be the same for width and height anyway, but the question is: Is there a way of getting the actual input width and height of the placed file? Given the following quote, I guess it might not be possible for the general case. So the followup question would be: Is there way to get the input dimensions for the specific case of a psd-file?

> [@simonhenke](#):
>
> I don’t know if there’s a way to avoid that, otherwise you could adjust the image resolution before placing (given, that you know the resolution of the placed image).
