Skip to main content
Inspiring
July 28, 2023
Question

Photoshop 24.7.0: C++-SDK: Background-layer available returns false if there is only a background-la

  • July 28, 2023
  • 1 reply
  • 586 views

In my plugin I have code which checks whether a background layer is available:

#include <PIActions.h>
#include <PISuites.h>

SPErr PhotoShopHelper::HasBackgroundLayer(bool& hasBackground)
{
    hasBackground = false;
    Auto_Desc result(false);
    Auto_Ref reference;
    SPErr error = sPSActionReference->PutProperty(reference.get(), classBackgroundLayer, keyBackground);
    if (error)
        return error;

    error = sPSActionReference->PutEnumerated(reference.get(), classDocument, typeOrdinal, enumTarget);
    if (error)
        return error;

    // ignore the error on purpose, we may not have a background layer
    (void)sPSActionControl->Get(&result, reference.get());
    if (result.get() != NULL)
    {
        Boolean hasKey = false;
        Logger::WriteToLog(QString("Check for Background Layer: -> Has Key"));

        error = sPSActionDescriptor->HasKey(result.get(), keyName, &hasKey);
        if (error)
        {
            return error;
        }

        if (hasKey)
        {
            hasBackground = true;
        }
    }
     return error;
}

 

Until Version 24.6, The HasKey returned true if there is a background-layer available.

In Version 24.7, it will return true only if there is another layer (or more) available. If there is only a background-layer, it will return false.

Expectaition would be that it will return true in all cases a Background-layer is availabe (as before 24.7)

This topic has been closed for replies.

1 reply

Inspiring
January 30, 2024

Hello,

I don't think there's any need for further testing after this line of code:

if (result.get() != NULL)

You are trying to retrieve a background layer. And if there is no background layer Photoshop will return NULL in result.

 

I haven't tested it on version 24.7. But my validation code ends at this line and everything works fine in version 25.2 with both single and multiple layers (with background layer present and absent).

Inspiring
January 31, 2024

This is correct, but the error appeared when there is only(!) a background-layer.

Anyway:

It seems to be fixed in the newer Versions of Photoshop (at least the problem does not appear anymore), so the problem is only in 24.7.0

Inspiring
January 31, 2024

Ah, the typical Photoshop API. 🙂
I can confirm from my experience that Photoshop has a strange, sometimes illogical, and incomplete C++ API.

 

Offtopic:

I found your post about porting the plugin to Windows. I have a slightly different problem. I am trying to port my Photoshop plugin from Windows to Mac. I'm very new to Mac and don't fully understand how things work there. My build system is also based on CMake and I was able to compile a binary dylib file, but judging by the examples, the plugin should be something like a folder with files (bundle?). Could you share an example of a CMake file that creates this folder structure? Also, it would be great to see your list of parameters for Rez (the Xcode project doesn't give detailed information about what parameters are used to compile the resource).