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

How to import the RoboDK API & toolbox?

#1
Hi, I think some months ago the default code when adding a new Python program in the RoboDK tree has been changed in how RoboDK packages are loaded and 'RDK' is assigned. (Post edit: as I read here now:Python API for RoboDK 5.4.0)

The 'old' lines of code are as below, and I could use e.g. ITEM_TYPE_PROGRAM to search for a robot program:

Code:
from robolink import * # RoboDK API
from robodk import * # Robot toolbox
RDK = Robolink()

prog = RDK.Item('myProgram',ITEM_TYPE_PROGRAM)
print('Program name: ' + prog.Name())
raise Exception('Eof exception.')

This still works fine, the program is found and its name gets printed. The version with the 'new' preamble is however:

Code:
from robodk import robolink # RoboDK API
从robodk进口robomath #机器人工具箱
RDK = robolink.Robolink()

prog = RDK.Item('myProgram',ITEM_TYPE_PROGRAM)
print('Program name: ' + prog.Name())
raise Exception('Eof exception.')

The latter results in an error:NameError: name 'ITEM_TYPE_PROGRAM' is not defined.
When I use:prog = RDK.Item('myProgram',8)using an integer 8 instead of the ITEM_TYPE_PROGRAM string, the item does get found.

Why do I get this error? And as it seems to have something to do with the loading of packages, how do you recommend to load the required packages?

Best regards,

Maarten


Messages In This Thread
How to import the RoboDK API & toolbox? - byMaarten- 06-22-2022, 10:13 AM



Users browsing this thread:
1 Guest(s)