How to place image programmatically into selected frame?

I’m using UXP to build plugin. It downloads image from given URL, then save it locally on user’s machine and then place into photoshop/indesign document.
And I need to implement new feature, fit this image into selected frame if it exists. For InDesign it works perfect

[image] = await indesign.app.selection[0].place(savedFile);
image.fit(indesign.FitOptions.FILL_PROPORTIONALLY);

But for Photoshop it’s nightmare. I didn’t find any similar method for fitting image inside selected frame, I’ve tried with uxp, photoshop scripts and batchPlay, nothing works. Is anyone here able to help me with this?

1 Like

Are you talking about frame tool in Photoshop?

Hey!
Yes, that’s right. This is a screenshot of plugin. When I click on download icon flow I described above happens. And I want to place image inside of this selected frame. But I couldn’t find how. I will be very grateful for any help here.

I never scripted this one… but from what I know your description about nightmare should be accurate.

1 Like

Yes, that’s true. And for me it’s super weird that for InDesign only two rows of code needed. And also it’s possible to do with old approach of building extensions with CEP and Extendscript. And with UXP it’s not.

To not repeat myself: Issues with .duplicate into a new doc - #5 by Jarda

There is probably no DOM API but you should be successfull with batchPlay. The command you probably need to use is File > Place Linked or File > Place Embedded. Depends on what you need.

Here is what Alchemist Listener recorded:

{
   "_obj": "placeEvent",
   "ID": 4,
   "null": {
      "_path": image-to-place,
      "_kind": "local"
   },
   "linked": true,
   "freeTransformCenterState": {
      "_enum": "quadCenterState",
      "_value": "QCSAverage"
   },
   "offset": {
      "_obj": "offset",
      "horizontal": {
         "_unit": "pixelsUnit",
         "_value": 0
      },
      "vertical": {
         "_unit": "pixelsUnit",
         "_value": 0
      }
   },
   "replaceLayer": {
      "_obj": "placeEvent",
      "from": {
         "_ref": "layer",
         "_id": 2
      },
      "to": {
         "_ref": "layer",
         "_id": 4
      }
   },
}

Hey, thanks for your response. Could you please help me with this line
"_path": image-to-place,
What should be in image-to-place? What object is it? or it’s just a path to image or what?

It’s the image path. You may need to create a token from the file entry for this.