Error using executeScriptString

Report crashes, strange behaviour, or apparent bugs
Post Reply
Juancho
Posts: 17
Joined: 11 Jun 2018, 03:14

Error using executeScriptString

Post 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

coppelia
Site Admin
Posts: 10467
Joined: 14 Dec 2012, 00:25

Re: Error using executeScriptString

Post 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

Juancho
Posts: 17
Joined: 11 Jun 2018, 03:14

Re: Error using executeScriptString

Post 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!

coppelia
Site Admin
Posts: 10467
Joined: 14 Dec 2012, 00:25

Re: Error using executeScriptString

Post 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

Juancho
Posts: 17
Joined: 11 Jun 2018, 03:14

Re: Error using executeScriptString

Post by Juancho »

I see, thanks for the support!

Post Reply