Zum Inhalt

UIUtilities

A class bundling multiple RoboDK related utility functions.

get_or_add_color_tile(name, parent=None) staticmethod

Get a color tile item from the RoboDK item tree or create it if it doesn't exist yet.

Parameters:

Name Type Description Default
name str

name of the color tile

required
parent Optional[robolink.robolink.Item]

parent of the color tile

None

Returns:

Type Description
Item

the color tile

Source code in core/ui/ui_util.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@staticmethod
def get_or_add_color_tile(name: str, parent: Optional[robolink.Item] = None) -> robolink.Item:
    """Get a color tile item from the RoboDK item tree or create it if it doesn't exist yet.

    Args:
        name: name of the color tile
        parent: parent of the color tile

    Returns:
        the color tile
    """
    return UIUtilities.get_or_add_object(name, UIUtilities.COLOR_TILE_CAD_FILE, parent)

get_or_add_cube_segment(name, parent=None) staticmethod

Get a cube segment item from the RoboDK item tree or create it if it doesn't exist yet.

Parameters:

Name Type Description Default
name str

name of the cube segment

required
parent Optional[robolink.robolink.Item]

parent of the cube segment

None

Returns:

Type Description
Item

the cube segment

Source code in core/ui/ui_util.py
82
83
84
85
86
87
88
89
90
91
92
93
@staticmethod
def get_or_add_cube_segment(name: str, parent: Optional[robolink.Item] = None) -> robolink.Item:
    """Get a cube segment item from the RoboDK item tree or create it if it doesn't exist yet.

    Args:
        name: name of the cube segment
        parent: parent of the cube segment

    Returns:
        the cube segment
    """
    return UIUtilities.get_or_add_object(name, UIUtilities.CUBE_SEGMENT_CAD_FILE, parent)

get_or_add_frame(name, parent=None) staticmethod

Get an frame item from the RoboDK item tree or create it if it doesn't exist yet.

Parameters:

Name Type Description Default
name str

name of the frame

required
parent Optional[robolink.robolink.Item]

parent of the frame

None

Returns:

Type Description
Item

the frame

Source code in core/ui/ui_util.py
55
56
57
58
59
60
61
62
63
64
65
66
@staticmethod
def get_or_add_frame(name: str, parent: Optional[robolink.Item] = None) -> robolink.Item:
    """Get an frame item from the RoboDK item tree or create it if it doesn't exist yet.

    Args:
        name: name of the frame
        parent: parent of the frame

    Returns:
        the frame
    """
    return UIUtilities.get_or_add_item(name, robolink.ITEM_TYPE_FRAME, parent=parent)

get_or_add_item(name, itemtype, parent=None, file=None) staticmethod

Get an item from the RoboDK item tree or create it if it doesn't exist yet.

Parameters:

Name Type Description Default
name str

the name of the item

required
itemtype int

the type of the item

required
parent Optional[robolink.robolink.Item]

the parent of the item

None
file Optional[str]

the path to the file to read the object from (e.g. STL file); only applicable if itemtype == robolink.ITEM_TYPE_OBJECT

None

Returns:

Type Description
Item

the desired item

Exceptions:

Type Description
ValueError

The RoboDK item could not be created.

ValueError

The retrieved RoboDK item is invalid.

Source code in core/ui/ui_util.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@staticmethod
def get_or_add_item(name: str, itemtype: int, parent: Optional[robolink.Item] = None, file: Optional[str] = None) -> robolink.Item:
    """Get an item from the RoboDK item tree or create it if it doesn't exist yet.

    Args:
        name: the name of the item
        itemtype: the type of the item
        parent: the parent of the item
        file: the path to the file to read the object from (e.g. STL file); only applicable if `itemtype == robolink.ITEM_TYPE_OBJECT`

    Returns:
        the desired item

    Raises:
        ValueError: The RoboDK item could not be created.
        ValueError: The retrieved RoboDK item is invalid.
    """
    item = RoboDKInterface.link.Item(name, itemtype)
    if not item.Valid():
        if itemtype == robolink.ITEM_TYPE_OBJECT:
            item = RoboDKInterface.link.AddFile(file, parent)
            item.setName(name)
        elif itemtype == robolink.ITEM_TYPE_FRAME:
            item = RoboDKInterface.link.AddFrame(name, parent)
        elif itemtype == robolink.ITEM_TYPE_TARGET:
            item = RoboDKInterface.link.AddTarget(name, parent)
        else:
            raise ValueError("Cannot create Item of type '{}'.".format(type(itemtype)))

    if item.Valid():
        if isinstance(parent, robolink.Item) and parent.Valid():
            item.setParent(parent)
        return item
    else:
        raise ValueError("Specified item is invalid: '{}'".format(name))

get_or_add_object(name, file, parent=None) staticmethod

Get an object item from the RoboDK item tree or create it if it doesn't exist yet.

Parameters:

Name Type Description Default
name str

name of the object

required
parent Optional[robolink.robolink.Item]

parent of the object

None
file str

the filepath of the object (e.g. STEP/STL/OBJ etc.)

required

Returns:

Type Description
Item

the object

Source code in core/ui/ui_util.py
68
69
70
71
72
73
74
75
76
77
78
79
80
@staticmethod
def get_or_add_object(name: str, file: str, parent: Optional[robolink.Item] = None) -> robolink.Item:
    """Get an object item from the RoboDK item tree or create it if it doesn't exist yet.

    Args:
        name: name of the object
        parent: parent of the object
        file: the filepath of the object (e.g. STEP/STL/OBJ etc.)

    Returns:
        the object
    """
    return UIUtilities.get_or_add_item(name, robolink.ITEM_TYPE_OBJECT, parent=parent, file=file)

set_pose(item, cs=None, x=0, y=0, z=0, rx=0, ry=0, rz=0, scaling=1) staticmethod

Set the pose of the specified RoboDK item using either a CoordinateSystem cs or x, y, z, rx, ry and rz.

In the latter case a scaling factor can be set. If the CoordinateSystem cs is given all other parameters are ignored.

Parameters:

Name Type Description Default
item Item

the item to set the position for

required
cs Optional[core.spatial.CoordinateSystem.CoordinateSystem]

coordinate system to read translation and rotation from

None
x float

translation along the x axis

0
y float

translation along the y axis

0
z float

translation along the z axis

0
rx float

rotation around x axis

0
ry float

rotation around y axis

0
rz float

rotation around z axis

0
scaling float

factor to apply to the translation

1
Source code in core/ui/ui_util.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@staticmethod
def set_pose(
        item: robolink.Item,
        cs: Optional[CoordinateSystem] = None,
        x: float = 0,
        y: float = 0,
        z: float = 0,
        rx: float = 0,
        ry: float = 0,
        rz: float = 0,
        scaling: float = 1):
    """Set the pose of the specified RoboDK item using either a `CoordinateSystem` cs or x, y, z, rx, ry and rz.

    In the latter case a scaling factor can be set.
    If the `CoordinateSystem` cs is given all other parameters are ignored.

    Args:
        item: the item to set the position for
        cs: coordinate system to read translation and rotation from
        x: translation along the x axis
        y: translation along the y axis
        z: translation along the z axis
        rx: rotation around x axis
        ry: rotation around y axis
        rz: rotation around z axis
        scaling: factor to apply to the translation
    """
    if isinstance(cs, CoordinateSystem):
        mat = robodk.Mat()
        mat.setVX(list(cs.base[:, 0]))
        mat.setVY(list(cs.base[:, 1]))
        mat.setVZ(list(cs.base[:, 2]))
        # set pos only accepts ints or floats (np.int64 is not supported)
        mat.setPos(list(map(int, cs.origin * scaling)))

        item.setPose(mat)
    else:
        item.setPose(robodk.KUKA_2_Pose([x*scaling, y*scaling, z*scaling, rz, ry, rx]))