Skip to main content
Participant
August 5, 2023
Question

How do I flip the canvas on my UXP plugin using js?

  • August 5, 2023
  • 2 replies
  • 731 views

I am working on my first plugin.  I am also new to js, so admittedly I'm still learning some things.  However, I have every part of my plugin complete but I cannot seem to figure out how I am supposed to flip the canvas.  I just want to write a function that flips the canvas horizontally (or vertically) when called.  What do i call to be able to do this?  I've searched through every available app.document or app.activeDocument option i could find.  Am i missing something?  Rather than a plugin, should i be implementing a script instead or can i integrate both together?

This topic has been closed for replies.

2 replies

Legend
August 5, 2023

You need to call batchPlay, because flipCanvas does not seem to exist.

 

const photoshop = require('photoshop') ;
const { app, core } = photoshop ;
const { batchPlay } = photoshop.action ;

// flip canvas direction
const Direction = {
  'HORIZONTAL': 'horizontal', 
  'VERTICAL': 'vertical'
} ;

/**
  * flip canvas
  *  {Document} doc target document
  *  {String} [direction] flip canvas direction. 'horizontal' if it is undefined
*/
const flipCanvas = async (doc, direction = Direction.HORIZONTAL) => {
  await batchPlay(
    [
      {
        "_obj": "flip",
        "_target": [
          {
            "_ref": "document",
            "_id": doc.id
          }
        ],
        "axis": {
          "_enum": "orientation",
          "_value": direction
        }
      }
    ], 

    {}
  ) ;
} ;

const main = async () => {
  try {
    await core.executeAsModal(
      async (control) => {
        await flipCanvas(app.activeDocument, Direction.HORIZONTAL) ;
      }, 

      {'commandName': 'Flip Canvas'}
    ) ;
  } catch(e) {
    await app.showAlert(e) ;
  }
} ;

 

Stephen Marsh
Community Expert
Community Expert
August 5, 2023

That's why I'm sticking with the old scripting for as long as I can, UXP certainly hasn't made things any easier for a non-programmer to get into.

Inspiring
August 6, 2023

uxp as I see it it's a failure it's been almost 3 years now and I don't see many programmers migrating to this system. the documentation is still under development and many features are still closed. Adobe needs to review this project.

Stephen Marsh
Community Expert
Community Expert
August 5, 2023

I don't know about UXP.

 

Standard JS DOM:

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/Document/flipCanvas.html

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/Direction.html#direction

 

Are you using Alchemist in your UXP development?

Participant
August 5, 2023

Funny you mention alchemist, just stumbled on it and installed it right before seeing your reply. I'm trying to understand how I incorporate it's code into a function I can run on a timer.

 

Thank you for your help btw.