• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

New Here ,
Aug 04, 2023 Aug 04, 2023

Copy link to clipboard

Copied

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?

TOPICS
Actions and scripting , macOS

Views

354

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Aug 04, 2023 Aug 04, 2023

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2023 Aug 04, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2023 Aug 05, 2023

Copy link to clipboard

Copied

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) ;
  }
} ;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2023 Aug 05, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 06, 2023 Aug 06, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2023 Aug 06, 2023

Copy link to clipboard

Copied

Personally, I feel that UXP’s batchPlay has made Photoshop more easily extendable programmatically. Scripting Listener, which had the impression of just recording and playing back, is now very easy to modify.

 

However, UXP definitely requires more knowledge and skills than ExtendScript. It takes a lot of energy to start the first step.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 06, 2023 Aug 06, 2023

Copy link to clipboard

Copied

LATEST

for simple tasks and as you say but you agree with me that uxp is still immature, Keep in mind that I often go to the uxp developer forum and every day I always see new problems, where even experienced programmers find problems, even simply with a new photoshop update. If they don't decide to give us simple and above all stable tools, I doubt that anyone can use uxp.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines