Page 1 of 1

Error using executeScriptString

Posted: 10 Jun 2024, 03:29
by Juancho
Hi there,

I'm using the ZeroMQ remote API (4.6.0-rev18) for C++. I'm having issues when using executeScriptString. I was wondering if I'm missing something or if there is a bug.

Minimal example:

(There is a Panda robot on the scene)

Code: Select all

#include "RemoteAPIClient.h"
#include <iostream>


int main()
{
    try
    {
        RemoteAPIClient client;
        auto sim = client.getObject().sim();
        sim.startSimulation();
        auto handle = sim.getObject("/Franka/connection");
        auto scriptHandle = sim.addScript(sim.scripttype_childscript);
        sim.associateScriptWithObject(scriptHandle, handle);
        sim.executeScriptString("--Hello there", scriptHandle);
        sim.stopSimulation();

    }
    catch (const std::runtime_error& e)
    {
        std::cerr << "Caught a runtime error: " << e.what() << std::endl;
    }

    return 0;
}

Output:

Code: Select all

Caught a runtime error: No such function: sim.executeScriptString
I appreciate the help you can provide me.

Best regards,

Juan

Re: Error using executeScriptString

Posted: 11 Jun 2024, 05:57
by coppelia
Hello Juan,

what happens if you call instead, e.g.:

Code: Select all

sim.executeScriptString("print('Hello there')", sim.getScript(sim.scripttype_sandboxscript));
Does this work or does it print anything in the statusbar?

The error message could be misleading, not sure what is going on on your side. However, when you have just created a script, it usually is not yet initialized. Before calling sim.executeScriptString, try calling sim.initScript(scriptHandle)

Within one week, we will release CoppeliaSim V4.7, which will feature script objects, i.e. scripts as scene objects on their own. This will make what you are trying to do less messy.

Cheers

Re: Error using executeScriptString

Posted: 11 Jun 2024, 16:17
by Juancho
Thank you for your reply.

I tried your suggestions, but the problem persists.

Code: Select all

#include "RemoteAPIClient.h"
#include <iostream>


int main()
{
    try
    {
        RemoteAPIClient client;
        auto sim = client.getObject().sim();
        sim.startSimulation();
        auto handle = sim.getObject("/Franka/connection");
        auto scriptHandle = sim.addScript(sim.scripttype_childscript);
        sim.associateScriptWithObject(scriptHandle, handle);
        sim.initScript(scriptHandle);
        sim.executeScriptString("print('Hello there')",
                                sim.getScript(sim.scripttype_sandboxscript));
        sim.stopSimulation();

    }
    catch (const std::runtime_error& e)
    {
        std::cerr << "Caught a runtime error: " << e.what() << std::endl;
    }

    return 0;
}
Output:

Code: Select all

Caught a runtime error: No such function: sim.executeScriptString
I'm going to test it on v4.7 once it is released. Thanks!

Re: Error using executeScriptString

Posted: 17 Jun 2024, 08:05
by coppelia
Just thought about something: some dangerous API functions are disabled by default, when called from an external source like from a remote API client. To enable those calls, make sure to set execUnsafeExt to true in usrset.txt (the location of that file can be found when typing sim.getStringParam(sim.stringparam_usersettingsdir) )

Cheers

Re: Error using executeScriptString

Posted: 18 Jun 2024, 16:57
by Juancho
I see, thanks for the support!