Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Setting robot path visible when running a python script using the API

#1
When running Python program within RoboDK, I can show/hide the program to show/hide the robot path and I can even toggle the visibility of an other Python program as such :

Code:
program = RDK.Item('name of a program that exists in the tree', ITEM_TYPE_PROGRAM_PYTHON)
program.setVisible(True)

However, I am interested in exectuting a program externally (with the API) and controlling the visibility of the robot path. How can that be achieved?

For context, I need to separate the Station rdk file from the program mostly for version control.
#2
You should be able to run any Python script externally from RoboDK the same way you can run them from inside of RoboDK.

The RoboDK API can be executed from a different process. If you use Python, simply make sure you have the robodk package installed from PyPi:
https://pypi.org/project/robodk/

You can also right click an RDK file and select Extract RoboDK Script(s) to automatically extract the Python scripts of your RoboDK project.
#3
Thanks for the info, I didn't know about the last part.
However my question is actually about the visibility of the path when using a Python script externally. I can't display the robot path when using an external script to move the robot. It is, however, very easy if I put the script within the RDK file and set it as visible using F7 or with the code provided in the question earlier. My goal is to use external scripts only, without extracting or reinserting the script in RoboDK everytime I want to see the path.

Is there a way to set the robot path visible when running a script externally?
#4
OK I understand better what you mean. The program path of Python files is only displayed when programs are run from RoboDK.

You could trigger an external program from RoboDK by simply running another Python script and you should be able to see the yellow program path:
Code:
import os, sys, subprocess

# Set the name of the driver (does not have to be Python)
python_file = "C:/RoboDK/Library/Scripts/Comau_LIS_Import.py"
program_run = "\"" + sys.executable + "\" \"" + python_file + "\""

print("Running command: " + program_run)

# Modify driver environment
environment = os.environ.copy()
#my_env["PATH"] = "/addtopath/folder:" + my_env["PATH"]

p = subprocess.Popen(program_run, shell=True, env=environment)
p.wait()
print("Done")


Attached Files
.py   RunPythonFile.py (Size: 474 bytes / Downloads: 116)
#5
Appreciate your answer.
I haven't been able to get the mentionned code to work. Just to make sure I understand a little better, our .rdk file would contain, as a Python script, the lines you mentionned in your last reply. That code would then execute our robot code stored in an external file. Correct?

Our setup would look like the following :
C://some custom dev path/simulation/station.rdk
C://some custom dev path/simulation/robot_task.py
where "some custom dev path" may be different for every developper
where "simulation" is a Git folder

I am unfamilliar with the drivers and what the "python_file" line means. Isn't that somthing that is already set within the ".rdk" file? I am also unsure of what happens with the manipulation of the env and why we need to do that. Do you mind explaining a bit more? Using subprocess.Popopen will run our Python code and display of the yellow path because it is run from the ".rdk" file, correct?

Thanks for your help
#6
The python_file variable in the example I provided previously should be the full path of the Python script you want to run externally. It is important to pass the environment to your subprocess to make sure you execute your script the same way RoboDK would execute it. You should then see the yellow path.
  




Users browsing this thread:
1 Guest(s)