uxp-photoshop-plugin-samples icon indicating copy to clipboard operation
uxp-photoshop-plugin-samples copied to clipboard

How do I call native commands like in a C++ plugin?

Open integral-llc opened this issue 2 years ago • 1 comments

I've been developing a C++ plugin to run a bunch of commands on current loaded file. i.e. if I want to load a custom color profile from a file I can run such a sequence

Auto_Desc convertDescriptor;
      DescriptorTypeID runtimeEventID;
      Auto_Ref convertReference;
      Auto_Desc convertResult(false);

      METHOD_INFO("Loading profile data of size") << dataLength << LOG_NL;

      SPErr error = sPSActionReference->PutIdentifier(convertReference, classDocument, docId);
      CHECK_ERROR("PutIdentifier", error)

      error = sPSActionDescriptor->PutReference(convertDescriptor, keyNull, convertReference);
      CHECK_ERROR("PutReference", error)

      error = sPSActionDescriptor->PutData(convertDescriptor, keyTo, dataLength, pData);
      CHECK_ERROR("PutData", error)

      error = sPSActionDescriptor->PutEnumerated(convertDescriptor, keyIntent, typeIntent, enumColorimetric);
      CHECK_ERROR("PutEnumerated", error)

      error = sPSActionDescriptor->PutBoolean(convertDescriptor, keyMapBlack, true);
      CHECK_ERROR("PutBoolean", error)

      error = sPSActionDescriptor->PutBoolean(convertDescriptor, keyDither, true);
      CHECK_ERROR("PutBoolean", error)

      error = sPSActionDescriptor->PutBoolean(convertDescriptor, keyFlatten, true);
      CHECK_ERROR("PutBoolean", error)

      error = sPSActionDescriptor->PutInteger(convertDescriptor, keyShadowMode, -1);
      CHECK_ERROR("PutInteger", error)

      error = sPSActionControl->StringIDToTypeID("convertToProfile", &runtimeEventID);
      CHECK_ERROR("StringIDToTypeID", error)

      error = sPSActionControl->Play(&convertResult, runtimeEventID, convertDescriptor, plugInDialogSilent);
      CHECK_ERROR("Play", error)

or if I want to load a selection I can run something like this

  bool PhotoShopBridge::LoadSelection(const LoadSelectionCommand &command) {
    METHOD_START("PhotoShopBridge::LoadSelection")

      Auto_Ref reference1;
      Auto_Ref reference2;
      Auto_Desc result(false);
      Auto_Desc descriptor;

      auto name = command.entityName();
      auto type = command.type();
      if (type.empty())
        type = "l";

      SPErr error = PIUSelectByID(classDocument, command.documentId());
      CHECK_ERROR("PIUSelectByID", error)

      error = sPSActionReference->PutProperty(reference1, classChannel, keySelection);
      CHECK_ERROR("PutProperty", error)

      error = sPSActionDescriptor->PutReference(descriptor, keyNull, reference1.get());
      CHECK_ERROR("PutReference", error)

      if (!name.empty()) {
        if (type == "l") {
          error = sPSActionReference->PutEnumerated(reference2, classChannel, typeChannel, enumTransparency);
          CHECK_ERROR("PutEnumerated", error)

          error = sPSActionReference->PutName(reference2, classLayer, name.c_str());
          CHECK_ERROR("PutName", error)
        } else {
          error = sPSActionReference->PutName(reference2, classChannel, name.c_str());
          CHECK_ERROR("PutName", error)
        }
      } else {
        error = sPSActionReference->PutEnumerated(reference2, classChannel, typeOrdinal, enumTarget);
        CHECK_ERROR("PutEnumerated", error)
      }

      error = sPSActionDescriptor->PutReference(descriptor, keyTo, reference2.get());
      CHECK_ERROR("PutReference", error)
      error = sPSActionControl->Play(&result, eventSet, descriptor, plugInDialogSilent);
      CHECK_ERROR("Play", error)

    METHOD_END
  }

the main downside for this plugin is that I cannot achieve a native look and feel for it. So I decided to give UXP a try, so far is was quite easy to create the needed interface and have a native look and feel, but I see no way of running a command as I do in the C++ plugin? Is there any solution for this?

So far, I have 2 plugins,

  • UXP - for UI and various parameters to be set by users
  • C++ - to execute various commands I need. for now, I managed to send commands from UXP to C++ and vice-versa and it works well, but then I don't know how to deploy correctly the C++ plugin? Can I download it with UXP version and run the installer as it has dependencies to 3rd party C++ libraries? If not, what's the process for it?

Or better yet, how do I execute all those commands from UXP using JavaScript.

Thx

integral-llc avatar Mar 20 '22 01:03 integral-llc

Nice timing! We're working on a new code sample and some documentation about hybrid UXP-C++ plugins at the moment. I just edited a blog post about it here: https://medium.com/adobetech/big-updates-coming-to-uxp-3185f0e47130?source=friends_link&sk=3d56221b756e9e997b9ccfc958c41f83

ErinFinnegan avatar Mar 23 '22 19:03 ErinFinnegan