get active document path in photoshop plugin using c++?

113 views Asked by At

I need to get the active document file path in photoshop using c++?

I know in JS we can get by app.activeDocument.Path, but not sure how to get the same info in c++?

1

There are 1 answers

0
JoergEwald On

This is what I found in some (rather ancient!) code I'm currently working on (not mine, still learning about Photoshop APIs myself). The last line is specific to macOS, no idea how that would look under Windows.

SPErr           error = kSPNoError;

PIActionReference       ref = NULL;
PIActionDescriptor      resDesc = NULL;
AliasHandle             srcAlias = NULL;

error = sPSActionReference->Make(&ref);
if (error == kSPNoError && ref != NULL)
{
    error = sPSActionReference->PutEnumerated(ref, classDocument, typeOrdinal, enumTarget);
}
if (error != kSPNoError)  goto earlyExit;

// get all the document properties and grab the interesting ones
error = sPSActionControl->Get(&resDesc, ref);
if (error == kSPNoError && resDesc != NULL)
{
    // for GetAlias() refer to PIUFile.cpp
    error = sPSActionDescriptor->GetAlias(resDesc, keyFileReference,
        (Handle *) srcAlias);
    if (error == errAEParamMissed)
    {
        error = saveDocFirstErr;
        goto earlyExit;
    }
}
if (error != kSPNoError)  goto earlyExit;

FSRef srcFSRef;
Boolean wasChanged;
error = FSResolveAlias(NULL, srcAlias, &srcFSRef, &wasChanged);