2.RoboDK API (robodk package)

Warning

The RoboDK API was refactored with version 5.4.0.

These changes are backward compatible, but not forward compatible. Effectively, the robolink.py module is now a sub-module of the robodk package (robodk.robolink), and robodk.py is now split into different sub-modules (robodk.robomath, robodk.robodialogs, robodk.robofileio).

You can access the documentation prior to version 5.4.0 here://www.sinclairbody.com/doc/en/PythonAPI/v0/index.html

Before 5.4.0

Most of our examples used the import method below:

fromrobolinkimport*fromrobodkimport*RDK=Robolink()pose=eye()我TEM_TYPE_ROBOT

After 5.4.0

You can use any of the following import methods:

fromrobodkimportrobolink,robomathRDK=robolink.Robolink()pose=robomath.eye()robolink.我TEM_TYPE_ROBOT
fromrobodk.robolinkimportRobolink,我TEM_TYPE_ROBOTfromrobodk.robomathimporteyeRDK=Robolink()pose=eye()我TEM_TYPE_ROBOT
fromrobodk.robolinkimport*fromrobodk.robomathimport*RDK=Robolink()pose=eye()我TEM_TYPE_ROBOT

The robodk package is the distributed entry point of the Python API. It is the common parent of all sub-packages and modules that constitute the Python API.

Overview of the RoboDK API:

2.2.robomath.py

The robomath module is a robotics toolbox for Python, based on Peter Corke’s Robotics Toolbox (regarding pose transformations):https://petercorke.com/toolboxes/robotics-toolbox/. The robomath sub-module includes the Mat class to represent transformations in 3D.

The following page provides a brief overview of the RoboDK API for Python://www.sinclairbody.com/offline-programming

A summary regarding the RoboDK API is available in the documentation://www.sinclairbody.com/doc/en/RoboDK-API.html

robodk.robomath. pi =3.141592653589793

PI

robodk.robomath. pause ( seconds )

Pause in seconds

Parameters

pause(float) – time in seconds

robodk.robomath. sqrt ( value )

Returns the square root of a value

robodk.robomath. sqrtA ( value )

Returns the square root of a value if it’s greater than 0, else 0 (differs from IEEE-754).

robodk.robomath. sin ( value )

Returns the sine of an angle in radians

robodk.robomath. cos ( value )

Returns the cosine of an angle in radians

robodk.robomath. tan ( value )

Returns the tangent of an angle in radians

robodk.robomath. asin ( value )

Returns the arc sine in radians

robodk.robomath. acos ( value )

Returns the arc cosinus in radians

robodk.robomath. atan2 ( y,x )

Returns angle of a 2D coordinate in the XY plane

robodk.robomath. name_2_id ( str_name_id )

Returns the number of a numbered object. For example: “Frame 3”, “Frame3”, “Fram3 3” returns 3.

robodk.robomath. rotx ( rx )

Returns a rotation matrix around the X axis (radians)

R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & c_\theta & -s_\theta & 0 \\ 0 & s_\theta & c_\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Parameters

rx(float) – rotation around X axis in radians

robodk.robomath. roty ( ry )

Returns a rotation matrix around the Y axis (radians)

R_y(\theta) = \begin{bmatrix} c_\theta & 0 & s_\theta & 0 \\ 0 & 1 & 0 & 0 \\ -s_\theta & 0 & c_\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Parameters

ry(float) – rotation around Y axis in radians

robodk.robomath. rotz ( rz )

Returns a rotation matrix around the Z axis (radians)

R_x(\theta) = \begin{bmatrix} c_\theta & -s_\theta & 0 & 0 \\ s_\theta & c_\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Parameters

ry(float) – rotation around Y axis in radians

robodk.robomath. transl ( tx,ty=None,tz=None )

Returns a translation matrix (mm)

T(t_x, t_y, t_z) = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix}

Parameters
  • tx(float) – translation along the X axis

  • ty(float) – translation along the Y axis

  • tz(float) – translation along the Z axis

See also

rotx(),roty(),rotz()

robodk.robomath. RelTool ( target_pose,x,y,z,rx=0,ry=0,rz=0 )

计算一个relative target with respect to the tool coordinates. This procedure has exactly the same behavior as ABB’s RelTool instruction. X,Y,Z are in mm, RX,RY,RZ are in degrees.

:paramMattarget_pose: Reference pose :param float x: translation along the Tool X axis (mm) :param float y: translation along the Tool Y axis (mm) :param float z: translation along the Tool Z axis (mm) :param float rx: rotation around the Tool X axis (deg) (optional) :param float ry: rotation around the Tool Y axis (deg) (optional) :param float rz: rotation around the Tool Z axis (deg) (optional)

robodk.robomath. Offset ( target_pose,x,y,z,rx=0,ry=0,rz=0 )

计算一个relative target with respect to the reference frame coordinates. X,Y,Z are in mm, RX,RY,RZ are in degrees.

:paramMattarget_pose: Reference pose :param float x: translation along the Reference X axis (mm) :param float y: translation along the Reference Y axis (mm) :param float z: translation along the Reference Z axis (mm) :param float rx: rotation around the Reference X axis (deg) (optional) :param float ry: rotation around the Reference Y axis (deg) (optional) :param float rz: rotation around the Reference Z axis (deg) (optional)

robodk.robomath. point_Xaxis_2_pose ( point,xaxis,zaxis_hint1=[0,0,-1],zaxis_hint2=[0,-1,0] )

Returns a pose given the origin as a point, a X axis and a preferred orientation for the Z axis

robodk.robomath. point_Yaxis_2_pose ( point,yaxis,zaxis_hint1=[0,0,-1],zaxis_hint2=[-1,0,0] )

Returns a pose given the origin as a point, a Y axis and a preferred orientation for the Z axis

robodk.robomath. point_Zaxis_2_pose ( point,zaxis,yaxis_hint1=[0,0,1],yaxis_hint2=[0,1,1] )

Returns a pose given the origin as a point, a Z axis and a preferred orientation for the Y axis

robodk.robomath. eye ( size=4 )

Returns the identity matrix

T(t_x, t_y, t_z) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Parameters

size(int) – square matrix size (4x4 Identity matrix by default, otherwise it is initialized to 0)

robodk.robomath. size ( matrix,dim=None )

Returns the size of a matrix (m,n). Dim can be set to 0 to return m (rows) or 1 to return n (columns)

Parameters
  • matrix(Mat) – pose

  • dim(int) – dimension

robodk.robomath. tr ( matrix )

Returns the transpose of the matrix

Parameters

matrix(Mat) – pose

robodk.robomath. invH ( matrix )

Returns the inverse of a homogeneous matrix

Parameters

matrix(Mat) – pose

robodk.robomath. catV ( mat1,mat2 )

Concatenate 2 matrices (vertical concatenation)

robodk.robomath. catH ( mat1,mat2 )

Concatenate 2 matrices (horizontal concatenation)

robodk.robomath. tic ( )

Start a stopwatch timer

robodk.robomath. toc ( )

Read the stopwatch timer

robodk.robomath. PosePP ( x,y,z,r,p,w )

Create a pose from XYZRPW coordinates. The pose format is the one used by KUKA (XYZABC coordinates). This is function is the same as KUKA_2_Pose (with the difference that the input values are not a list). This function is used as “p” by the intermediate file when generating a robot program.

robodk.robomath. pose_2_xyzrpw ( H )

Calculates the equivalent position (mm) and Euler angles (deg) as an [x,y,z,r,p,w] array, given a pose. It returns the values that correspond to the following operation: transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180)

Parameters

H(Mat) – pose

Returns

[x,y,z,r,p,w] in mm and deg

robodk.robomath. xyzrpw_2_pose ( xyzrpw )

Calculates the pose from the position (mm) and Euler angles (deg), given a [x,y,z,r,p,w] array. The result is the same as calling: H = transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180)

robodk.robomath. Pose ( x,y,z,rxd,ryd,rzd )

Returns the pose (Mat) given the position (mm) and Euler angles (deg) as an array [x,y,z,rx,ry,rz]. The result is the same as calling: H = transl(x,y,z)*rotx(rx*pi/180)*roty(ry*pi/180)*rotz(rz*pi/180) This pose format is printed for homogeneous poses automatically. This Pose is the same representation used by Mecademic or Staubli robot controllers.

Parameters
  • tx(float) – position (X coordinate)

  • ty(float) – position (Y coordinate)

  • tz(float) – position (Z coordinate)

  • rxd(float) – first rotation in deg (X coordinate)

  • ryd(float) – first rotation in deg (Y coordinate)

  • rzd(float) – first rotation in deg (Z coordinate)

robodk.robomath. TxyzRxyz_2_Pose ( xyzrpw )

Returns the pose given the position (mm) and Euler angles (rad) as an array [x,y,z,rx,ry,rz]. The result is the same as calling: H = transl(x,y,z)*rotx(rx)*roty(ry)*rotz(rz)

Parameters

xyzrpw(list of float) – [x,y,z,rx,ry,rz] in mm and radians

robodk.robomath. Pose_2_TxyzRxyz ( H )

Retrieve the position (mm) and Euler angles (rad) as an array [x,y,z,rx,ry,rz] given a pose. It returns the values that correspond to the following operation: H = transl(x,y,z)*rotx(rx)*roty(ry)*rotz(rz).

Parameters

H(Mat) – pose

robodk.robomath. Pose_2_Staubli ( H )

Converts a pose (4x4 matrix) to a Staubli XYZWPR target

Parameters

H(Mat) – pose

robodk.robomath. Staubli_2_Pose ( xyzwpr )

Converts a Staubli XYZWPR target to a pose (4x4 matrix)

Parameters

H(Mat) – pose

robodk.robomath. Pose_2_Motoman ( H )

Converts a pose (4x4 matrix) to a Motoman XYZWPR target (mm and deg)

Parameters

H(Mat) – pose

robodk.robomath. Pose_2_Fanuc ( H )

Converts a pose (4x4 matrix) to a Fanuc XYZWPR target (mm and deg)

Parameters

H(Mat) – pose

robodk.robomath. Pose_2_Techman ( H )

Converts a pose (4x4 matrix) to a Techman XYZWPR target (mm and deg)

Parameters

H(Mat) – pose

robodk.robomath. Motoman_2_Pose ( xyzwpr )

Converts a Motoman target to a pose (4x4 matrix)

robodk.robomath. Fanuc_2_Pose ( xyzwpr )

Converts a Fanuc target to a pose (4x4 matrix)

robodk.robomath. Techman_2_Pose ( xyzwpr )

Converts a Techman target to a pose (4x4 matrix)

robodk.robomath. Pose_2_KUKA ( H )

Converts a pose (4x4 matrix) to an XYZABC KUKA target (Euler angles), required by KUKA KRC controllers.

Parameters

H(Mat) – pose

robodk.robomath. KUKA_2_Pose ( xyzrpw )

Converts a KUKA XYZABC target to a pose (4x4 matrix), required by KUKA KRC controllers.

robodk.robomath. Adept_2_Pose ( xyzrpw )

Converts an Adept XYZRPW target to a pose (4x4 matrix)

robodk.robomath. Pose_2_Adept ( H )

Converts a pose to an Adept target

Parameters

H(Mat) – pose

robodk.robomath. Comau_2_Pose ( xyzrpw )

Converts a Comau XYZRPW target to a pose (4x4 matrix), the same representation required by PDL Comau programs.

robodk.robomath. Pose_2_Comau ( H )

Converts a pose to a Comau target, the same representation required by PDL Comau programs.

Parameters

H(Mat) – pose

robodk.robomath. Pose_2_Nachi ( pose )

Converts a pose to a Nachi XYZRPW target

Parameters

pose(Mat) – pose

robodk.robomath. Nachi_2_Pose ( xyzwpr )

Converts a Nachi XYZRPW target to a pose (4x4 matrix)

robodk.robomath. pose_2_quaternion ( Ti )

Returns the quaternion orientation vector of a pose (4x4 matrix)

Parameters

Ti(Mat) – pose

robodk.robomath. Pose_Split ( pose1,pose2,delta_mm=1.0 )

Create a sequence of poses that transitions from pose1 to pose2 by steps of delta_mm in mm (the first and last pose are not included in the list)

robodk.robomath. quaternion_2_pose ( qin )

Returns the pose orientation matrix (4x4 matrix) given a quaternion orientation vector

Parameters

qin(list) – quaternions as 4 float values

robodk.robomath. Pose_2_ABB ( H )

Converts a pose to an ABB target (using quaternion representation).

Parameters

H(Mat) – pose

robodk.robomath. print_pose_ABB ( pose )

Displays an ABB RAPID target (the same way it is displayed in IRC5 controllers).

Parameters

pose(Mat) – pose

robodk.robomath. Pose_2_UR ( pose )

Calculate the p[x,y,z,u,v,w] position with rotation vector for a pose target. This is the same format required by Universal Robot controllers.

robodk.robomath. UR_2_Pose ( xyzwpr )

Calculate the pose target given a p[x,y,z,u,v,w] cartesian target with rotation vector. This is the same format required by Universal Robot controllers.

robodk.robomath. dh ( rz,tx=None,tz=None,rx=None )

Returns the Denavit-Hartenberg 4x4 matrix for a robot link. calling dh(rz,tx,tz,rx) is the same as using rotz(rz)*transl(tx,0,tz)*rotx(rx) calling dh(rz,tx,tz,rx) is the same as calling dh([rz,tx,tz,rx])

robodk.robomath. dhm ( rx,tx=None,tz=None,rz=None )

Returns the Denavit-Hartenberg Modified 4x4 matrix for a robot link (Craig 1986).

calling dhm(rx,tx,tz,rz) is the same as using rotx(rx)*transl(tx,0,tz)*rotz(rz)

calling dhm(rx,tx,tz,rz) is the same as calling dhm([rx,tx,tz,rz])

robodk.robomath. joints_2_angles ( jin,type )

Converts the robot encoders into angles between links depending on the type of the robot.

robodk.robomath. angles_2_joints ( jin,type )

Converts the angles between links into the robot motor space depending on the type of the robot.

robodk.robomath. norm ( p )

Returns the norm of a 3D vector

robodk.robomath. normalize3 ( a )

Returns the unitary vector

robodk.robomath. cross ( a,b )

Returns the cross product of two 3D vectors

robodk.robomath. dot ( a,b )

Returns the dot product of two 3D vectors

robodk.robomath. angle3 ( a,b )

Returns the angle in radians of two 3D vectors

robodk.robomath. pose_angle ( pose )

Returns the angle in radians of a 4x4 matrix pose

Parameters

pose(Mat) – pose

robodk.robomath. pose_angle_between ( pose1,pose2 )

Returns the angle in radians between two poses (4x4 matrix pose)

robodk.robomath. mult3 ( v,d )

Multiplies a 3D vector to a scalar

robodk.robomath. subs3 ( a,b )

Subtracts two 3D vectors c=a-b

robodk.robomath. add3 ( a,b )

Adds two 3D vectors c=a+b

robodk.robomath. distance ( a,b )

Calculates the distance between two points

robodk.robomath. pose_is_similar ( a,b,tolerance=0.1 )

Check if the pose is similar. Returns True if both poses are less than 0.1 mm or 0.1 deg appart. Optionally provide the tolerance in mm+deg

robodk.robomath. intersect_line_2_plane ( pline,vline,pplane,vplane )

Calculates the intersection betweeen a line and a plane

robodk.robomath. proj_pt_2_plane ( point,planepoint,planeABC )

Projects a point to a plane

robodk.robomath. proj_pt_2_line ( point,paxe,vaxe )

Projects a point to a line

robodk.robomath. fitPlane ( points )

Returns the equation and normal for a best fit plane to a cloud of points.

Uses singular value decomposition to produce a least squares fit to a plane. Points must have centroid at [0, 0, 0]. Must provide at least 4 points.

Parameters

points(array-like) – a 3xN array of points. Each column represents one point.

Returns

pplane: the equation of the best-fit plane, in the form b(1)*X + b(2)*Y +b(3)*Z + b(4) = 0.

Return type

array_like

Returns

vplane: the normal vector of the best-fit plane.

Return type

list of floats

exception robodk.robomath. MatrixError

An exception class for Matrix

class robodk.robomath. Mat ( rows=None,ncols=None )

Mat is a matrix object. The main purpose of this object is to represent a pose in the 3D space (position and orientation).

A pose is a 4x4 matrix that represents the position and orientation of one reference frame with respect to another one, in the 3D space.

Poses are commonly used in robotics to place objects, reference frames and targets with respect to each other.

Example:

fromrobodk.robolinkimport*# import the robolink libraryfromrobodk.robomathimport*# import the robomath libraryRDK=Robolink()# connect to the RoboDK APIrobot=RDK.我tem('',我TEM_TYPE_ROBOT)# Retrieve a robot available in RoboDK#target = RDK.Item('Target 1') # Retrieve a target (example)pose=robot.Pose()# retrieve the current robot position as a pose (position of the active tool with respect to the active reference frame)# target = target.Pose() # the same can be applied to targets (taught position)# Read the 4x4 pose matrix as [X,Y,Z , A,B,C] Euler representation (mm and deg): same representation as KUKA robotsXYZABC=Pose_2_KUKA(pose)print(XYZABC)# Read the 4x4 pose matrix as [X,Y,Z, q1,q2,q3,q4] quaternion representation (position in mm and orientation in quaternion): same representation as ABB robots (RAPID programming)xyzq1234=Pose_2_ABB(pose)print(xyzq1234)# Read the 4x4 pose matrix as [X,Y,Z, u,v,w] representation (position in mm and orientation vector in radians): same representation as Universal Robotsxyzuvw=Pose_2_UR(pose)print(xyzuvw)x,y,z,a,b,c=XYZABC# Use the KUKA representation (for example) and calculate a new pose based on the previous poseXYZABC2=[x,y,z+50,a,b,c+45]pose2=KUKA_2_Pose(XYZABC2)# Convert the XYZABC array to a pose (4x4 matrix)robot.MoveJ(pose2)# Make a joint move to the new position# target.setPose(pose2) # We can also update the pose to targets, tools, reference frames, objects, ...
__init__ ( rows=None,ncols=None )
copy ( )
ColsCount ( )

Return the number of coumns. Same as len().

RowsCount ( )

Return the number of rows

Cols ( )

Retrieve the matrix as a list of columns (list of list of float).

Example:

>>>transl(10,20,30).Rows()[[1, 0, 0, 10], [0, 1, 0, 20], [0, 0, 1, 30], [0, 0, 0, 1]]>>>transl(10,20,30).Cols()[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [10, 20, 30, 1]]
Rows ( )

Get the matrix as a list of lists

tr ( )

Returns the transpose of the matrix

size ( dim=None )

Returns the size of a matrix (m,n). Dim can be set to 0 to return m (rows) or 1 to return n (columns)

catV ( mat2 )

Concatenate with another matrix (vertical concatenation)

catH ( mat2 )

Concatenate with another matrix (horizontal concatenation)

eye ( m=4 )

Make identity matrix of size (mxm)

isHomogeneous ( )

returns 1 if it is a Homogeneous matrix

RelTool ( x,y,z,rx=0,ry=0,rz=0 )

计算一个relative target with respect to the tool coordinates. This procedure has exactly the same behavior as ABB’s RelTool instruction. X,Y,Z are in mm, RX,RY,RZ are in degrees.

Parameters
  • x(float) – translation along the Tool X axis (mm)

  • y(float) – translation along the Tool Y axis (mm)

  • z(float) – translation along the Tool Z axis (mm)

  • rx(float) – rotation around the Tool X axis (deg) (optional)

  • ry(float) – rotation around the Tool Y axis (deg) (optional)

  • rz(float) – rotation around the Tool Z axis (deg) (optional)

See also

Offset()

Offset ( x,y,z,rx=0,ry=0,rz=0 )

计算一个relative target with respect to this pose. X,Y,Z are in mm, RX,RY,RZ are in degrees.

Parameters
  • x(float) – translation along the Reference X axis (mm)

  • y(float) – translation along the Reference Y axis (mm)

  • z(float) – translation along the Reference Z axis (mm)

  • rx(float) – rotation around the Reference X axis (deg) (optional)

  • ry(float) – rotation around the Reference Y axis (deg) (optional)

  • rz(float) – rotation around the Reference Z axis (deg) (optional)

See also

RelTool()

invH ( )

Returns the inverse of this pose (homogeneous matrix assumed)

inv ( )

Returns the inverse of this pose (homogeneous matrix assumed)

tolist ( )

Returns the first column of the matrix as a list

list ( )

Returns the first column of the matrix as a list

list2 ( )

Returns the matrix as list of lists (one list per column)

Pos ( )

Returns the position of a pose (assumes that a 4x4 homogeneous matrix is being used)

VX ( )

Returns the X vector of a pose (assumes that a 4x4 homogeneous matrix is being used)

VY ( )

Returns the Y vector of a pose (assumes that a 4x4 homogeneous matrix is being used)

VZ ( )

Returns the Z vector of a pose (assumes that a 4x4 homogeneous matrix is being used)

Rot33 ( )

Returns the sub 3x3 rotation matrix

setPos ( newpos )

Sets the XYZ position of a pose (assumes that a 4x4 homogeneous matrix is being used)

setVX ( v_xyz )

Sets the VX vector of a pose, which is the first column of a homogeneous matrix (assumes that a 4x4 homogeneous matrix is being used)

setVY ( v_xyz )

Sets the VY vector of a pose, which is the first column of a homogeneous matrix (assumes that a 4x4 homogeneous matrix is being used)

setVZ ( v_xyz )

Sets the VZ vector of a pose, which is the first column of a homogeneous matrix (assumes that a 4x4 homogeneous matrix is being used)

translationPose ( )

Return the translation pose of this matrix. The rotation returned is set to identity (assumes that a 4x4 homogeneous matrix is being used)

rotationPose ( )

Return the rotation pose of this matrix. The position returned is set to [0,0,0] (assumes that a 4x4 homogeneous matrix is being used)

SaveCSV ( strfile )

Save theMatMatrix to a CSV (Comma Separated Values) file. The file can be easily opened as a spreadsheet such as Excel.

See also

SaveMat(),SaveList(),LoadList(),LoadMat()

SaveMat ( strfile,separator=',' )

Save theMat矩阵CSV或TXT文件

See also

SaveCSV(),SaveList(),LoadList(),LoadMat()

2.3.robodialogs.py

的robodialogs sub-module是对话框的工具箱。我t contains, open and save file dialogs, message prompts, input dialogs etc.

robodk.robodialogs. FILE_TYPES_ALL =('AllFiles','.*')

File type filter for all files

robodk.robodialogs. FILE_TYPES_ROBODK =('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py')

File type filter for RoboDK files

robodk.robodialogs. FILE_TYPES_3D_OBJECT =('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml')

File type filter for 3D object files

robodk.robodialogs. FILE_TYPES_TEXT =('TextFiles','.txt.csv')

File type filter for text files

robodk.robodialogs. FILE_TYPES_IMG =('ImageFiles','.png.jpg')

File type filter for image files

robodk.robodialogs. FILE_TYPES_CAM =('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc')

File type filter for CAD/CAM files

robodk.robodialogs. FILE_TYPES_ROBOT =('RobotFiles','.mod.src.ls.jbi.prm.script.urp')

File type filter for robot files

robodk.robodialogs. getOpenFile ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )

Deprecated since version 5.5:Obsolete. UsegetOpenFileName ()instead.

Pop up a file dialog window to select a file to open. Returns a file object opened in read-only mode. Use returned value.name to retrieve the file path.

Parameters
  • path_preference(str) – The initial folder path, optional

  • strfile(str) – The initial file name (with extension), optional

  • strtitle(str) – The dialog title, optional

  • defaultextension(str) – The initial file extension filter, e.g. ‘.*’

  • filetypes(list of tuples of str) – The available file type filters, e.g. ‘[(‘All Files’, ‘.*’), (‘Text Files’, ‘.txt .csv’)]’

Returns

An read-only handle to the file, or None if the user cancels

Return type

TextIOWrapper

robodk.robodialogs. getSaveFile ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='SaveAs',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )

Deprecated since version 5.5:Obsolete. UsegetSaveFileName()instead.

弹出一个对话框窗口选择一个文件save. Returns a file object opened in write-only mode. Use returned value.name to retrieve the file path.

Parameters
  • path_preference(str) – The initial folder path, optional

  • strfile(str) – The initial file name (with extension), optional

  • strtitle(str) – The dialog title, optional

  • defaultextension(str) – The initial file extension filter, e.g. ‘.*’

  • filetypes(list of tuples of str) – The available file type filters, e.g. ‘[(‘All Files’, ‘.*’), (‘Text Files’, ‘.txt .csv’)]’

Returns

An write-only handle to the file, or None if the user cancels

Return type

TextIOWrapper

robodk.robodialogs. getOpenFileName ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )

Pop up a file dialog window to select a file to open. Returns the file path as a string.

Parameters
  • path_preference(str) – The initial folder path, optional

  • strfile(str) – The initial file name (with extension), optional

  • strtitle(str) – The dialog title, optional

  • defaultextension(str) – The initial file extension filter, e.g. ‘.*’

  • filetypes(list of tuples of str) – The available file type filters, e.g. ‘[(‘All Files’, ‘.*’), (‘Text Files’, ‘.txt .csv’)]’

Returns

The file path, or None if the user cancels

Return type

str

robodk.robodialogs. getOpenFileNames ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile(s)',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )

Pop up a file dialog window to select one or more file to open. Returns the file path as a list of string.

Parameters
  • path_preference(str) – The initial folder path, optional

  • strfile(str) – The initial file name (with extension), optional

  • strtitle(str) – The dialog title, optional

  • defaultextension(str) – The initial file extension filter, e.g. ‘.*’

  • filetypes(list of tuples of str) – The available file type filters, e.g. ‘[(‘All Files’, ‘.*’), (‘Text Files’, ‘.txt .csv’)]’

Returns

A list of file path(s), or None if the user cancels

Return type

list of str

robodk.robodialogs. getSaveFileName ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='SaveAs',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )

弹出一个对话框窗口选择一个文件save. Returns the file path as a string.

Parameters
  • path_preference(str) – The initial folder path, optional

  • strfile(str) – The initial file name (with extension), optional

  • strtitle(str) – The dialog title, optional

  • defaultextension(str) – The initial file extension filter, e.g. ‘.*’

  • filetypes(list of tuples of str) – The available file type filters, e.g. ‘[(‘All Files’, ‘.*’), (‘Text Files’, ‘.txt .csv’)]’

Returns

The file path, or None if the user cancels

Return type

str

robodk.robodialogs. getOpenFolder ( path_preference='C:/RoboDK/Library/',strtitle='OpenFolder' )

Pop up a folder dialog window to select a folder to open. Returns the path of the folder as a string.

Parameters
  • path_preference(str) – The initial folder path, optional

  • strtitle(str) – The dialog title, optional

Returns

The folder path, or None if the user cancels

Return type

str

See also

getSaveFolder()

robodk.robodialogs. getSaveFolder ( path_preference='C:/RoboDK/Library/',strtitle='SavetoFolder',**kwargs )

Pop up a folder dialog window to select a folder to save into. Returns the path of the folder as a string.

Parameters
  • path_preference(str) – The initial folder path, optional

  • strtitle(str) – The dialog title, optional

Returns

The folder path, or None if the user cancels

Return type

str

See also

getOpenFolder()

robodk.robodialogs. ShowMessage ( msg,title=None )

Show a blocking message, with an ‘OK’ button.

Parameters
  • msg(str) – The message to be displayed

  • title(str) – The window title, optional

Returns

True

Return type

bool

robodk.robodialogs. ShowMessageOkCancel ( msg,title=None )

Show a blocking message, with ‘OK’ and ‘Cancel’ buttons.

Parameters
  • msg(str) – The message to be displayed

  • title(str) – The window title, optional

Returns

True if the user clicked ‘OK’, false for everything else

Return type

bool

See also

ShowMessage()

robodk.robodialogs. ShowMessageYesNo ( msg,title=None )

Show a blocking message, with ‘Yes’ and ‘No’ buttons.

Parameters
  • msg(str) – The message to be displayed

  • title(str) – The window title, optional

Returns

True if the user clicked ‘Yes’, false for everything else

Return type

bool

robodk.robodialogs. ShowMessageYesNoCancel ( msg,title=None )

Show a blocking message, with ‘Yes’, ‘No’ and ‘Cancel’ buttons.

Parameters
  • msg(str) – The message to be displayed

  • title(str) – The window title, optional

Returns

True for ‘Yes’, false for ‘No’, and None for ‘Cancel’

Return type

bool

robodk.robodialogs. mbox ( msg,b1='OK',b2='Cancel',frame=True,t=False,entry=None,*args,**kwargs )

Deprecated since version 5.5:Obsolete. Use我nputDialog()instead.

Create an instance of MessageBox, and get data back from the user.

Parameters
  • msg(str) – string to be displayed

  • b1(str,tuple) – left button text, or a tuple (, )

  • b2(str,tuple) – right button text, or a tuple (, )

  • frame(bool) – include a standard outerframe: True or False

  • t(int,float) – time in seconds (int or float) until the msgbox automatically closes

  • entry(None,bool,str) – include an entry widget that will provide its contents returned. Provide text to fill the box

See also

我nputDialog()

robodk.robodialogs. 我nputDialog ( msg,value,title=None,default_button=False,default_value=None,embed=False,actions=None,*args,**kwargs )

Show a blocking input dialog, with ‘OK’ and ‘Cancel’ buttons.

The input field is automatically created for supported types:
  • Base types: bool, int, float, str

  • list or tuple of base types

  • dropdown formatted as [int, [str, str, …]]. e.g. [1, [‘Option #1’, ‘Option #2’]] where 1 means the default selected option is Option #2.

  • dictionary of supported types, where the key is the field’s label. e.g. {‘This is a bool!’ : True}.

Parameters
  • msg(str) – Message to the user (describes what to enter)

  • value– Initial value of the input (see supported types)

  • title(embed) – Window title, optional

  • default_button– Show a button to reinitialize the input to default, defaults to false

  • default_value– Default values to restore. If not provided, the original values will be used

  • title– Embed the window inside RoboDK, defaults to false

  • actions(list of tuples of str,callable) – List of optional action callbacks to add as buttons, formatted as [(str, callable), …]. e.g. [(“Button #1”, action_1), (“Button #2”, action_2)]

Returns

The user input if the user clicked ‘OK’, None for everything else

Return type

See supported types

Example:

print(我nputDialog('This is as input dialog.\n\nEnter an integer:',0))print(我nputDialog('This is as input dialog.\n\nEnter a float:',0.0))print(我nputDialog('This is as input dialog.\n\nEnter text:',''))print(我nputDialog('This is as input dialog.\n\nSet a boolean:',False))print(我nputDialog('This is as input dialog.\n\nSelect from a dropdown:',[0,['RoboDK is the best','I love RoboDK!',"Can't hate it, can I?"]]))print(我nputDialog('This is as input dialog.\n\nSet multiple entries:',{'Enter an integer:':0,'Enter a float:':0.0,'Set a boolean:':False,'Enter text:':'','Select from a dropdown:':[0,['RoboDK is the best!','I love RoboDK!',"Can't hate it, can I?"]],'Edit int list:':[0,0,0],'Edit float list:':[0.,0.],}))
class robodk.robodialogs. DialogsTk
static getOpenFile ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getSaveFile ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='SaveAs',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getOpenFileName ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getOpenFileNames ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile(s)',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getSaveFileName ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='SaveAs',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getOpenFolder ( path_preference='C:/RoboDK/Library/',strtitle='OpenFolder' )
static getSaveFolder ( path_preference='C:/RoboDK/Library/',strtitle='SavetoFolder' )
static ShowMessage ( msg,title=None )
static ShowMessageOkCancel ( msg,title=None )
static ShowMessageYesNo ( msg,title=None )
static ShowMessageYesNoCancel ( msg,title=None )
class MessageBox ( msg,b1,b2,frame,t,entry )
__init__ ( msg,b1,b2,frame,t,entry )
b1_action ( event=None )
b2_action ( event=None )
close_mod ( )
time_out ( )
to_clip ( event=None )
class 我nputDialogTk ( msg,value,actions=None,default=False,default_value=None,title=None,parent=None )
__init__ ( msg,value,actions=None,default=False,default_value=None,title=None,parent=None )

Construct a toplevel widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, menu, relief, screen, takefocus, use, visual, width.

accept ( event=None )
reject ( event=None )
reset ( )
mainloop ( n=0 )

Call the mainloop of Tk.

static 我nputDialog ( msg,value,title=None,default_button=False,default_value=None,embed=False,actions=None,*args,**kwargs )
static mbox ( msg,b1='OK',b2='Cancel',frame=True,t=False,entry=None )
class robodk.robodialogs. DialogsQt
static convert_filetypes ( filetypes,defaultextension=None )

Converts a Tkinter format for file types to a Qt format

static getOpenFileName ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getOpenFileNames ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='OpenFile(s)',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getSaveFileName ( path_preference='C:/RoboDK/Library/',strfile='',strtitle='SaveAs',defaultextension='.*',filetypes=[('AllFiles','.*'),('RoboDKFiles','.sld.rdk.robot.tool.rdka.rdkbak.rdkp.py'),('3DObjectFiles','.sld.stl.iges.igs.step.stp.obj.slp.3ds.dae.blend.wrl.wrml'),('TextFiles','.txt.csv'),('ImageFiles','.png.jpg'),('CAMFiles','.cnc.nc.apt.gcode.ngc.nci.anc.dxf.aptsource.cls.acl.cl.clt.ncl.knc'),('RobotFiles','.mod.src.ls.jbi.prm.script.urp')] )
static getOpenFolder ( path_preference='C:/RoboDK/Library/',strtitle='OpenFolder' )
static getSaveFolder ( path_preference='C:/RoboDK/Library/',strtitle='SavetoFolder' )
static ShowMessage ( msg,title=None )
static ShowMessageOkCancel ( msg,title=None )
static ShowMessageYesNo ( msg,title=None )
static ShowMessageYesNoCancel ( msg,title=None )
class 我nputDialogQt ( msg,value,title=None,default_button=False,default_value=None,actions=None,parent=None,f=PySide2.QtCore.Qt.WindowType.Dialog )
__init__ ( msg,value,title=None,default_button=False,default_value=None,actions=None,parent=None,f=PySide2.QtCore.Qt.WindowType.Dialog )
staticMetaObject =object>
reset ( )
showEvent ( self,arg__1:PySide2.QtGui.QShowEvent ) None
static 我nputDialog ( msg,value,title=None,default_button=False,default_value=None,embed=False,actions=None,*args,**kwargs )

2.4.robofileio.py

The robofileio sub-module is a file operation toolbox. It contains file properties, CSV exporter, FTP, etc.

robodk.robofileio. searchfiles ( pattern='C:\\RoboDK\\Library\\*.rdk' )

List the files in a directory with a given extension

robodk.robofileio. getFileDir ( filepath )

Returns the directory of a file path

robodk.robofileio. getBaseName ( filepath )

Returns the file name and extension of a file path

robodk.robofileio. getFileName ( filepath )

Returns the file name (with no extension) of a file path

robodk.robofileio. DateModified ( filepath,stringformat=False )

Returns the time that a file was modified

robodk.robofileio. DateCreated ( filepath,stringformat=False )

Returns the time that a file was created

robodk.robofileio. DirExists ( folder )

Returns true if the folder exists

robodk.robofileio. FileExists ( file )

Returns true if the file exists

robodk.robofileio. FilterName ( namefilter,safechar='P',reserved_names=None )

Get a safe program or variable name that can be used for robot programming

robodk.robofileio. LoadList ( strfile,separator=',',codec='utf-8' )

Load data from a CSV file or a TXT file to a Python list (list of list of numbers)

Example:

csvdata=LoadList(strfile,',')values=[]foriinrange(len(csvdata)):print(csvdata[i])values.append(csvdata[i])# We can also save the list back to a CSV file# SaveList(csvdata, strfile, ',')
robodk.robofileio. SaveList ( list_variable,strfile,separator=',' )

Save a list or a list of lists as a CSV or TXT file.

robodk.robofileio. LoadMat ( strfile,separator=',' )

Load data from a CSV file or a TXT file to aMatMatrix

See also

LoadList()

robodk.robofileio. RemoveFileFTP ( ftp,filepath )

Delete a file on a remote server.

robodk.robofileio. RemoveDirFTP ( ftp,path )

Recursively delete a directory tree on a remote server.

robodk.robofileio. UploadDirFTP ( localpath,server_ip,remote_path,username,password )

Upload a folder to a robot through FTP recursively

robodk.robofileio. UploadFileFTP ( file_path_name,server_ip,remote_path,username,password )

Upload a file to a robot through FTP

robodk.robofileio. UploadFTP ( program,robot_ip,remote_path,ftp_user,ftp_pass,pause_sec=2 )

Upload a program or a list of programs to the robot through FTP provided the connection parameters

2.5.roboapps.py

The roboapps sub-module is a RoboDK Apps toolbox. More info here:https://github.com/RoboDK/Plug-In-Interface/tree/master/PluginAppLoader

Warning

The roboapps sub-module is specific to the Python API.

class robodk.roboapps. RunApplication ( rdk=None )

Class to detect when the terminate signal is emitted to stop an action.

RUN=RunApplication()whileRUN.Run():# your main loop to run until the terminate signal is detected...
__init__ ( rdk=None )
RDK =None
time_last =-1
param_name =None
Run ( )

Run callback.

Returns

True as long as the App is permitted to run.

Return type

bool

robodk.roboapps. Unchecked ( )

Verify if the command “Unchecked” is present. In this case it means the action was just unchecked from RoboDK (applicable to checkable actions only).

Example for a ‘Checkable Action’:

defrunmain():ifroboapps.Unchecked():ActionUnchecked()else:roboapps.SkipKill()# Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()
robodk.roboapps. Checked ( )

Verify if the command “Checked” is present. In this case it means the action was just checked from RoboDK (applicable to checkable actions only).

Example for a ‘Checkable Action’:

defrunmain():ifroboapps.Unchecked():ActionUnchecked()else:roboapps.SkipKill()# Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()
robodk.roboapps. KeepChecked ( )

Keep an action checked even if the execution of the script completed (applicable to checkable actions only).

Example for a ‘Checkable Option’:

defrunmain():ifroboapps.Unchecked():ActionUnchecked()else:roboapps.KeepChecked()# Important, prevents RoboDK from unchecking the action after it has completedActionChecked()
robodk.roboapps. SkipKill ( )

For Checkable actions, this setting will tell RoboDK App loader to not kill the process a few seconds after the terminate function is called. This is needed if we want the user input to save the file. For example: The Record action from the Record App.

Example for a ‘Momentary Action’:

defrunmain():ifroboapps.Unchecked():roboapps.Exit()# or sys.exit()else:roboapps.SkipKill()# Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()
robodk.roboapps. Exit ( exit_code=0 )

Exit/close the action gracefully. If an error code is provided, RoboDK will display a trace to the user.

robodk.roboapps. Str2FloatList ( str_values,expected_nvalues=3 )

Convert a string into a list of floats. It returns None if the array is smaller than the expected size.

Parameters
  • str_values(list of str) – The string containing a list of floats

  • expected_nvalues(int,optional) – Expected number of values in the string list, defaults to 3

Returns

The list of floats

Return type

list of float

robodk.roboapps. Registry ( varname,setvalue=None )

Read value from the registry or set a value. It will do so at HKEY_CURRENT_USER so no admin rights required.

robodk.roboapps. value_to_widget ( value,parent )

Convert a value to a widget (Tkinter or Qt).

The widget is automatically created for supported types: - Base types: bool, int, float, str - list or tuple of base types - dropdown formatted as [int, [str, str, …]]. e.g. [1, [‘Option #1’, ‘Option #2’]] where 1 means the default selected option is Option #2. - dictionary of supported types, where the key is the field’s label. e.g. {‘This is a bool!’ : True}.

Parameters
  • value(see supported types) – The value to convert as a widget, and the initial value of the widget

  • parent– Parent of the widget (Qt/Tkinter)

Returns

(widget, funcs) the widget, and a list of ‘get’ functions to retrieve the value of the widget

Return type

tuple of widget (Qt/Tkinter), callable

robodk.roboapps. widget_to_value ( funcs,original_value )

Retrieve the value from a widget’s list of get functions. The original value is required to recreate the original format.

Parameters
Returns

The value

robodk.roboapps. get_robodk_theme ( RDK=None )

Get RoboDK’s active theme (Options->General->Theme)

robodk.roboapps. get_qt_app ( robodk_icon=True,robodk_theme=True,RDK=None )

Get the QApplication instance.

Note: If RoboDK is not running, The RoboDK theme is not applied.

Parameters
  • robodk_icon(bool) – Applies the RoboDK logo, defaults to True

  • robodk_theme(bool) – Applies the current RoboDK theme, defaults to True

  • RDK(robolink.Robolink) – Link to the running RoboDK instance for the theme, defaults to None

Returns

The QApplication instance

Return type

PySide2.QtWidgets.QApplication

robodk.roboapps. set_qt_theme ( app,RDK=None )

设置一个Qt应用主题匹配RoboDK’s theme.

Parameters

app(PySide2.QtWidgets.QApplication) – The QApplication

robodk.roboapps. get_qt_robodk_icon ( icon_name,RDK=None )

Retrieve a RoboDK icon by name, such as robot, tool and frame icons (requires Qt module).

Parameters

icon_name(str) – The name of the icon

Returns

a QImage of the icon if it succeeds, else None

Return type

PySide2.QtGui.QImage

robodk.roboapps. get_qt_robodk_icons ( RDK=None )

Retrieve a dictionary of available RoboDK icons, such as robot, tool and frame icons (requires Qt module).

Returns

a dictionary of QImage of available icons

Return type

dict ofPySide2.QtGui.QImage

robodk.roboapps. value_to_qt_widget ( value,parent=None )

Convert a value to a widget. For instance, a float into a QDoubleSpinBox, a bool into a QCheckBox.

The widget is automatically created for supported types: - bool, int, float, str (base types) - list or tuple of base types - dropdown formatted as [int, [str, str, …]] i.e. [1, [‘Option #1’, ‘Option #2’]] where 1 means the default selected option is Option #2. - dictionary of supported values, formatted as {label:value}

Returns

(widget, funcs) the widget, and a list of get functions to retrieve the value of the widget

robodk.roboapps. get_tk_app ( robodk_icon=True,robodk_theme=True,RDK=None )

Get the QApplication instance.

Parameters
  • robodk_icon(bool) – Applies the RoboDK logo, defaults to True

  • robodk_theme(bool) – Applies the current RoboDK theme, defaults to True

  • RDK(robolink.Robolink) – Link to the running RoboDK instance for the theme, defaults to None

Returns

The QApplication instance

Return type

PySide2.QtWidgets.QApplication

robodk.roboapps. value_to_tk_widget ( value,frame )

Convert a value to a widget. For instance, a float into a Spinbox, a bool into a Checkbutton.

The widget is automatically created for supported types: - bool, int, float, str (base types) - list or tuple of base types - dropdown formatted as [int, [str, str, …]] i.e. [1, [‘Option #1’, ‘Option #2’]] where 1 means the default selected option is Option #2. - dictionary of supported values, formatted as {label:value}

Returns

(widget, funcs) the widget, and a list of get functions to retrieve the value of the widget

class robodk.roboapps. AppSettings ( settings_param='App-Settings' )

Generic application settings class to save and load settings to a RoboDK station with a built-in UI.

Parameters

settings_param(str) – RoboDK parameter used to store this app settings. It should be unique if you have more than one App setting.

Example:

classSettings(AppSettings):def__init__(self,settings_param='My-App-Settings'):super().__init__(settings_param=settings_param)# List the variable names you would like to save and their default values.# Variables that start with underscore (_) will not be saved.self.BOOL=Trueself.我NT=123456self.FLOAT=0.123456789self.STRING='Text'self.我NT_LIST=[1,2,3]self.FLOAT_LIST=[1.0,2.0,3.0]self.STRING_LIST=['First line','Second line','Third line']self.MIXED_LIST=[False,1,'2']self.我NT_TUPLE=(1,2,3)self.DROPDOWN=[1,['First line','Second line','Third line']]self.DICT={'This is a string':'Text','This is a float':0.0}# Variable names when displayed on the user interface (detailed descriptions).# Create this dictionary in the same order that you want to display it.# If AppSettings._FIELDS_UI is not provided, all variables of this class will be used displayed with their attribute name.# Fields within dollar signs (i.e. $abc$) are used as section headers.fromcollectionsimportOrderedDictself._FIELDS_UI=OrderedDict()self._FIELDS_UI['SECTION_1']='$This is a section$'self._FIELDS_UI['BOOL']='This is a bool'self._FIELDS_UI['INT']='This is an int'self._FIELDS_UI['FLOAT']='This is a float'self._FIELDS_UI['STRING']='This is a string'self._FIELDS_UI['INT_LIST']='This is an int list'self._FIELDS_UI['FLOAT_LIST']='This is a float list'self._FIELDS_UI['STRING_LIST']='This is a string list'self._FIELDS_UI['MIXED_LIST']='This is a mixed list'self._FIELDS_UI['INT_TUPLE']='This is an int tuple'self._FIELDS_UI['SECTION_2']='$This is another section$'self._FIELDS_UI['DROPDOWN']='This is a dropdown'self._FIELDS_UI['DICT']='This is a dictionary'S=Settings()S.Load()# Load previously saved settings from RoboDKS.ShowUI('Settings for my App')print(S.BOOL)
__init__ ( settings_param='App-Settings' )
CopyFrom ( other )

Copy settings from another AppSettings instance.

Parameters

other(robodk.roboapps.AppSettings) – The other AppSettings instance

SetDefaults ( )

Set defaults settings. Attributes in ‘AppSettings._ATTRIBS_SKIP_DEFAULT’, if defined, are ignored.

GetDefaults ( )

Get the default settings.

getAttribs ( )

Get the list of all attributes (settings). Attributes that starts with ‘_’ are ignored.

Returns

all attributes

Return type

list of str

get ( attrib,default_value=None )

Get attribute value by key, otherwise it returns None

Save ( rdk=None,autorecover=False )

Save the class attributes as a RoboDK binary parameter in the specified station. If the station is not provided, it uses the active station.

Parameters
  • rdk(Robolink,optional) – Station to save to, defaults to None

  • autorecover(bool,optional) – Create a backup in the station, defaults to False

Load ( rdk=None )

Load the class attributes from a RoboDK binary parameter. If the station is not provided, it uses the active station.

Parameters

rdk(Robolink,optional) – Station to load from, defaults to None

Returns

True if it succeeds, else false.

Erase ( rdk=None )

Completely erase the stored settings and its backup from RoboDK.

ShowUI ( windowtitle=None,embed=False,show_default_button=True,actions=None,*args,**kwargs )

Show the Apps Settings in a GUI.

Parameters
  • windowtitle(str) – Window title, defaults to the Settings name

  • embed(bool) – Embed the settings window in RoboDK, defaults to False

  • show_default_button(bool) – Set to true to add a Default button to reset the fields, defaults to True

  • actions(list of tuples of str,callable) – List of optional action callbacks to add as buttons, formatted as [(str, callable), …]. e.g. [(“Button #1”, action_1), (“Button #2”, action_2)]

Returns

False if the user cancelled, else True.

robodk.roboapps. ShowExample ( )
robodk.roboapps. runmain ( )

2.6.robolinkutils.py

The robolinkutils sub-module provides utility functions using the Robolink module.

Warning

The robolinkutils sub-module is specific to the Python API.

Get all the items of a specific type for which getLink() returns the specified item.

Parameters
  • item(我tem) – The source Item

  • type_linked(int) – type of items to check for a link. None means any type.

Returns

A list of Items for which item.getLink return the specified item

Return type

list of我tem

robodk.robolinkutils. getAncestors ( item,parent_types=None )

Get the list of parents of an Item up to the Station, with type filtering (i.e. [ITEM_TYPE_FRAME, ITEM_TYPE_ROBOT, ..]). By default, it will return all parents of an Item with no regard to their type, ordered from the Item’s parent to the Station.

Parameters
  • item(我tem) – The source Item

  • parent_types(list of ITEM_TYPE_*,optional) – The parent allowed types, such as ITEM_TYPE_FRAME, defaults to None

Returns

A list of parents, ordered from the Item’s parent to the Station.

Return type

list of我tem

robodk.robolinkutils. getLowestCommonAncestor ( item1,item2 )

Finds the lowest common ancestor (LCA) between two Items in the Station’s tree.

Parameters
  • item1(我tem) – The first Item

  • item2(我tem) – The second Item

Returns

The lowest common ancestor (LCA)

Return type

我tem

robodk.robolinkutils. getAncestorPose ( item_child,item_parent )

Gets the pose between two Items that have a hierarchical relationship in the Station’s tree. There can be N Items between the two. This function will throw an error for synchronized axis.

Parameters
  • item_child(我tem) – The child Item

  • item_parent(我tem) – The parent Item

Returns

The pose from the child to the parent

Return type

robomath.Mat

robodk.robolinkutils. getPoseWrt ( item1,item2 )

Gets the pose of an Item (item1) with respect to an another Item (item2).

child.PoseWrt(child.Parent())# will return a forward pose from the parent to the childchild.Parent().PoseWrt(child)# will return an inverse pose from the child to the parenttool.PoseWrt(tool.Parent())# will return the PoseTool() of the tooltool.PoseWrt(station)# will return the absolute pose of the tool
Parameters
  • item1(robolink.Item) – The source Item

  • item2(robolink.Item) – The second Item

Returns

The pose from the source Item to the second Item

Return type

robomath.Mat

robodk.robolinkutils. setPoseAbsIK ( item,pose_abs )

Set the pose of the item with respect to the absolute reference frame, accounting for inverse kinematics. For instance, you can set the absolute pose of a ITEM_TYPE_TOOL directly without accounting for the robot kinematics. This function will throw an error for synchronized axis.

tool_item.setPoseAbs(eye(4))# will SET the tool center point with respect to the station at [0,0,0,0,0,0]setPoseAbsIK(tool_item,eye(4))# will MOVE the robot so that the tool center point with regard to the station is [0,0,0,0,0,0]
Parameters
  • item(robolink.Item) – The source Item

  • pose_abs(robomath.Mat) – pose of the item with respect to the station reference

robodk.robolinkutils. SolveIK_Conf ( robot,pose,toolpose=None,framepose=None,joint_config=[0,1,0] )

Calculates the inverse kinematics for the specified robot and pose. The function returns only the preferred solutions from the joint configuration as a 2D matrix. Returns a list of joints as a 2D matrix [N x M], where N is the number of degrees of freedom (robot joints) and M is the number of solutions. For some 6-axis robots, SolveIK returns 2 additional values that can be ignored.

Parameters
  • robot(robolink.Item) – The robot Item

  • pose(Mat) – pose of the robot flange with respect to the robot base frame

  • toolpose(Mat) – Tool pose with respect to the robot flange (TCP)

  • framepose(Mat) – Reference pose (reference frame with respect to the robot base)

  • joint_config(list of int) – desired joint configuration, as [Front(0)/Rear(1)/Any(-1), Elbow Up(0)/Elbow Down(1)/Any(-1), Non-flip(0)/Flip(1)/Any(-1)]