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

Issue Passing String from ExtendScript to Custom After Effects Plugin via ExternalObject

Community Beginner ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

I'm attempting to pass a string, such as "testCommand," from a JavaScript (ExtendScript) script to a custom After Effects plugin written in C++. Below is my current JavaScript code:

var command = "testCommand";
var pluginPath = "C:/Program Files/Adobe/Common/Plug-ins/7.0/MediaCore/SaveImage/";
var libFilename = "SaveImage.aex";
var consoleLib = new ExternalObject("lib:" + pluginPath + libFilename);
var utf8Command = encodeURIComponent(command);
consoleLib.setCommandString(utf8Command);
consoleLib.unload();

I would appreciate guidance or examples on how to receive this string within the plugin using C++.

TOPICS
Scripting , SDK

Views

163

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

correct answers 1 Correct answer

Community Beginner , Dec 04, 2024 Dec 04, 2024

I managed to pass a string, here is the code that worked
The documentation was especially helpful
https://extendscript.docsforadobe.dev/integrating-external-libraries/defining-entry-points-for-indirect-access.html 
https://extendscript.docsforadobe.dev/integrating-external-libraries/defining-entry-points-for-direct-access.html 

Plugin code

#include "SaveImage.h"
#include <Windows.h>

#define kTypeString 4                // Define the type constant for strings
static AEGP_PluginID S_my_id = 0L;
static
...

Votes

Translate

Translate
Enthusiast ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

How is the `.setCommandString` function implemented on the C++ side?  Its function signature needs to have a parameter as `TaggedData` type.   That data type has members that you set and then return the value.

 

The examples in the SDK show this function:

 

    /**
     * Appends a string onto the passed argument.
     *
     * This function only accepts a single argument, a String.  The passed argument
     * is appended with another string and then returned back to the scripting environment.
     * To call from Javascript&colon;
     *
     \code
     myObj.appendString("A String");
     \endcode
     *
     * If the arguments are not correct then a bad argument error code is returned.
     *
     * \param argv - The JavaScript argument
     * \param argc the argument count
     * \param retval The return value to be passed back to JavaScript
     */
    extern "C" BASICEXTERNALOBJECT_API long appendString(TaggedData* argv, long argc, TaggedData * retval)
    {
        // Accept 1 and only 1 argument
        if(argc != 1)
        {
            return kESErrBadArgumentList;
        }
        
        // The argument must be a string
        if(argv[0].type != kTypeString)
        {
            return kESErrBadArgumentList;
        }
        
        // The returned value type
        retval->type = kTypeString;
        
        // argv[0].data.string = the string passed in from the script
        string s (argv[0].data.string);
        
        // add a little bit of data onto the passed in string
        s.append("_appended by BasicExternalObject");
        
        retval->data.string = getNewBuffer(s);
        
        return kESErrOK;
    }

   

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 Beginner ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

I've tried different approaches, but so far I haven't been able to get a working result. I managed to pass a double variable, but I can't pass text. I've tried different text encodings, but it seems that's not the issue. Here are the characters I get instead of the text: �Q? �

here is my code

#include "SaveImage.h"
#include <Windows.h>
#include <string>

static AEGP_PluginID g_plugin_id = 0L;
static SPBasicSuite* g_sp_basic_suite = nullptr;

std::wstring ConvertToWString(const char* str) {

    int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0);
    std::wstring wide_string(len - 1, L' ');
    MultiByteToWideChar(CP_UTF8, 0, str, -1, &wide_string[0], len);

    return wide_string;
}

extern "C" __declspec(dllexport) const wchar_t* appendString(const char* input_string) {

    std::wstring modified_string = ConvertToWString(input_string);
    MessageBoxW(NULL, modified_string.c_str(), L"Debug", MB_OK);

    return 0;
}

A_Err EntryPointFunc(
    struct SPBasicSuite* pica_basicP,
    A_long major_versionL,
    A_long minor_versionL,
    AEGP_PluginID aegp_plugin_id,
    AEGP_GlobalRefcon* global_refconV
) {
    g_plugin_id = aegp_plugin_id;
    g_sp_basic_suite = pica_basicP;
    AEGP_SuiteHandler suites(pica_basicP);

    return A_Err_NONE;
}

 

var pluginPath = "C:/Program Files/Adobe/Common/Plug-ins/7.0/MediaCore/SaveImage/";
var pluginLibName = "SaveImage.aex";
var pluginLib = new ExternalObject("lib:" + pluginPath + pluginLibName);
                
var inputString = "My text";
pluginLib.appendString(inputString);



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 Beginner ,
Dec 04, 2024 Dec 04, 2024

Copy link to clipboard

Copied

LATEST

I managed to pass a string, here is the code that worked
The documentation was especially helpful
https://extendscript.docsforadobe.dev/integrating-external-libraries/defining-entry-points-for-indir... 
https://extendscript.docsforadobe.dev/integrating-external-libraries/defining-entry-points-for-direc... 

Plugin code

#include "SaveImage.h"
#include <Windows.h>

#define kTypeString 4                // Define the type constant for strings
static AEGP_PluginID S_my_id = 0L;
static SPBasicSuite* sP = NULL;

// TaggedData structure (provided by Adobe) https://extendscript.docsforadobe.dev/integrating-external-libraries/defining-entry-points-for-indirect-access.html
typedef struct {
    union {
        long intval;       // Integer value
        double fltval;     // Floating-point value
        char* string;      // String value
    } data;                // Data field
    long type;             // Data type
    long filler;           // Padding for alignment
} TaggedData;

// Exported function for JavaScript to call
extern "C" __declspec(dllexport) long processString(
    TaggedData * argv, 
    long argc, 
    TaggedData * retval)
{
    // Extract the string from the arguments
    const char* receivedString = argv[0].data.string;

    // Debug
    MessageBoxA(NULL, receivedString, "Received String", MB_OK);
    return 0;
}

A_Err EntryPointFunc(
    struct SPBasicSuite* pica_basicP, 
    A_long major_versionL, 
    A_long minor_versionL, 
    AEGP_PluginID aegp_plugin_id, 
    AEGP_GlobalRefcon* global_refconV)
{
    S_my_id = aegp_plugin_id;
    sP = pica_basicP;
    return A_Err_NONE;
}


Extension code

var pluginPath = "C:/Program Files/Adobe/Common/Plug-ins/7.0/MediaCore/SaveImage/";
var libFilename = "SaveImage.aex";
var pluginLib = new ExternalObject("lib:" + pluginPath + libFilename);

var command = "My text";
var result = pluginLib.processString(command);
pluginLib.unload();

 

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