Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run python script from RDK C++ API
#1
Hello , I need to execute python script embedded in RDK project but from application uses RDK C++ API. Is it possible do this somehow?
#2
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)
#3
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_API::Item>(robodk_instance_->getItem(QString::fromStdString(remote_rdk_patner_->RobotName_), RoboDK_API::RoboDK::ITEM_TYPE_ROBOT));
auto robot_program_python_ = std::make_shared<RoboDK_API::Item>(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 ) ?
  




Users browsing this thread:
1 Guest(s)