• 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

New Here ,
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

120

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
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:
     *
     \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
New Here ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

LATEST

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