RoboDK Forum
Run python script from RDK C++ API可打印版本

+- RoboDK Forum (//m.sinclairbody.com/forum)
+-- Forum: RoboDK (EN) (//m.sinclairbody.com/forum/Forum-RoboDK-EN)
+--- Forum: RoboDK API (//m.sinclairbody.com/forum/Forum-RoboDK-API)
+--- Thread: Run python script from RDK C++ API (/Thread-Run-python-script-from-RDK-C-API)



Run python script from RDK C++ API-backspace-09-05-2021

Hello , I need to execute python script embedded in RDK project but from application uses RDK C++ API. Is it possible do this somehow?


RE: Run python script from RDK C++ API-Vineet-09-07-2021

Using ITEM_TYPE_PROGRAM_PYTHON, you can retrieve the Python Script and run it.

Code:
ITEM_TYPE_STATION=1 # station item (.rdk files)
ITEM_TYPE_ROBOT=2 # robot item (.robot files)
ITEM_TYPE_FRAME=3 # reference frame item
ITEM_TYPE_TOOL=4 # tool item (.tool files or tools without geometry)
ITEM_TYPE_OBJECT=5 # object item (.stl, .step, .iges, ...)
ITEM_TYPE_TARGET=6 # target item
ITEM_TYPE_PROGRAM=8 # program item (made using the GUI)
ITEM_TYPE_PROGRAM_PYTHON=10 # Python program or macro
Example: item_py =RDK.Item('',ITEM_TYPE_PROGRAM_PYTHON)


RE: Run python script from RDK C++ API-backspace-09-08-2021

I tried this by doing like below ( this is just for testing purposes snippet ) :

Code:
if (robodk_instance_->Connected())
{
( ..... )

robot_instance_ = std::make_shared(robodk_instance_->getItem(QString::fromStdString(remote_rdk_patner_->RobotName_), RoboDK_API::RoboDK::ITEM_TYPE_ROBOT));
auto robot_program_python_ = std::make_shared(robodk_instance_->getItem(QString::fromStdString("InitParam"), RoboDK_API::RoboDK::ITEM_TYPE_PROGRAM_PYTHON));
robot_program_python_->RunProgram();

( ..... )
}

where 'InitParam' is a pythin script. When I run this script from RoboDK perspective it works. Script is going to show window used for providing parameters for "worker" script. So executing this via RDK API i would expect to see the same behavior but unfortunately i don't see anything except some strange effect like I would run 'worker' script - maybe its side effect of ...->RunProgram() ...
To be honest i'm not sure if RunProgram() can execute selected python script or its just dedicated for running generated programs.

So my question is if just taking/selecting item via .Item(... ) can should run python script or there is additional call required ( like RunProgram or something else ) ?