RoboDK Forum
How to import the RoboDK API & toolbox?- Printable Version

+- RoboDK Forum (//www.sinclairbody.com/forum)
+-- Forum: RoboDK (EN) (//www.sinclairbody.com/forum/Forum-RoboDK-EN)
+--- Forum: RoboDK API (//www.sinclairbody.com/forum/Forum-RoboDK-API)
+--- Thread: How to import the RoboDK API & toolbox? (/Thread-How-to-import-the-RoboDK-API-toolbox)



How to import the RoboDK API & toolbox?-Maarten-06-22-2022

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
从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:
从robodk import robolink # RoboDK API
从robodk import robomath # Robot toolbox
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


RE: How to import the RoboDK API & toolbox?-Sam-06-22-2022

Hi Maarten,

You need to use robolink.ITEM_TYPE_PROGRAM.


RE: How to import the RoboDK API & toolbox?-Maarten-06-22-2022

Hi Sam, thanks, that does the trick. So with the new package updates I can either use 'robolink.ITEM_TYPE_PROGRAM' or the corresponding integer ('8' in this case) when searching an item?


RE: How to import the RoboDK API & toolbox?-Sam-06-22-2022

No, there is no guarantee that the corresponding integer will not change in the future.

This has more to do with the way the python modules are imported. More info here://www.sinclairbody.com/doc/en/PythonAPI/robodk.html#robodk-api-robodk-package


RE: How to import the RoboDK API & toolbox?-Maarten-06-28-2022

Hi Sam, in follow up to your last reply: When using Type() to determine what type an item is, it returns the integer value, not ITEM_TYPE_*. If there is no guarantee that the integer values will not change in the future, how can these be avoided when determining the type of an item?


RE: How to import the RoboDK API & toolbox?-Sam-06-28-2022

You need to compare the return from Item.Type() with a robolink.ITEM_TYPE_* in your code.

Code:
if item.Type() == robolink.ITEM_TYPE_ROBOT:
print("this is a robot")