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

python paths, printing, debugging etc.

Hi, a few questions.. I'm currently writing python scripts by adding a python program item in the interface. 

1. If I add a print or sys.stderr.write(), where does it go? I tried starting Robodk from a shell, but I don't see any output from my statements in the shell. I guess I could make a console with tkinter but I'd prefer something simpler if it exists. 

2. I noticed references to console mode in the docs but I can't find documentation on using it. Is console mode a way to interact with Robodk through a python shell?

2. I tried using Robolink.Selection()
but I get the error: 'Robolink' object has no attribute 'Selection'
I notice in /Applications/ there is ./ and also ./robolink/ The first file has Selection() and the second doesn't. What is the difference? and Why do my scripts find the version without Selection() when in my preferences I have Python folder path set to: /Applications/ ? 

Many thanks!!

Some solutions

1. I set up logger to write to a file and then tail -f in a shell to see the results.

3. I removed ./robolink/ and now it just uses ./ where Selection() can be found.
Hi Julian,

To display messages from your Python program to RoboDK window you can use the following command:
Robolink.ShowMessage("Your message", blocking = True)
If you set it to non-blocking the message will be displayed in the status bar of the RoboDK window. If you start a Python script from RoboDK, all the prints done in Python (stdout, stderr) are shown only if your script fails.

You can start your own Python program independently and interact with RoboDK using the RoboDK API for Python. The RoboDK API uses internal TCP/IP communication so you could even control RoboDK remotely. You'll find some additional settings in:
  • RoboDK-Preferences-Other-RoboDK API (if you are using a Mac)
  • Tools-Options-Other-RoboDK API (for Windows and Linux)
If you want to run Python programs separately while interacting with RoboDK you should install the RoboDK API for Python:
pip install robodk

There are some command line options to start RoboDK:
For example, this allows you to keep RoboDK hidden while you set up your project.

On Mac, RoboDK automatically uses the following folder as the Python Path when you start a Python script from RoboDK:

Also, The latest version of RoboDK for Mac (v3.4.6) properly includes the Robolink.Selection() method.

Hi Albert,

This all makes a lot more sense now. I installed the Python API and can talk to Robodk from a Python shell. I guess it means I can also communicate with Robodk directly from within Maya, for example, to convert animations to targets, or export models.

Yes, it is possible to combine RoboDK with Maya. 
You can use the RoboDK API for Python to integrate Maya and RoboDK at the same time. 

So if you want to run Python scripts using the Robolink and Robodk libraries outside RoboDK you may have to install the RoboDK API for Python as you would install any other Python library using pip:
cd path-to-python-pip
pip install robodk

Let me know if you face any challenges and I can help.
Thanks Albert! It's all going good so far. I've written scripts to regenerate Maya objects in RoboDK: transforms to frames, locators to targets, meshes to shapes. Next, I'll be sending Maya curves as curveFollow projects. I'm happy to make this code public (when its cleaned up) if it's of use to anyone.


Users browsing this thread:
1 Guest(s)