laiye rpa
streamline your operations, improve productivity
many people will create plug-ins for ie/chrome/firefox browsers, eclipse, visual studio, sublime text and other programming tools. these plug-ins at the application tool level rely on the original platform to run, but they expand and enrich the original tools, functions, and platforms. based on plug-ins, users can even create personalized browsers and programming tools in a customized manner.
in fact, most programming languages also provide a plug-in mechanism, which we generally call a "class library". for example, java language, in addition to providing the most basic language features, also provides an extremely rich official core library. these core libraries cover network communication, file processing, encryption, decryption, serialization, and logging, so that almost everything is included. however, even with such a complete and powerful java official core library, there are still many users who still find it insufficient or difficult to use for their own specific application scenarios. therefore, some programmers, according to their application needs and scene characteristics, build a certain part of a function. this function can be very powerful and sometimes matches or surpasses the official core library. these users have extracted and contributed this part of the function, which is included in a recognized third-party class library. these third-party class libraries and the official core library together form a prosperous java ecosystem. the same is true for javascript and python.
let's go back to laiye rpa again. as mentioned earlier, laiye rpa is essentially a platform tool. this platform has several characteristics. the first characteristic is "powerful". laiye rpa provides many components for building rpa processes, and a large set of function modules, such as basic keyboard and mouse operations, various interface element operations, common office software and browser automation operations, various data processing, file processing, and network and system operations. the second characteristic of this platform is "simple". laiye rpa extracts the most versatile, common, basic, and core functions and integrates them into the platform to form a concise and capable core library. if you blindly pile up functions and integrate all functions, big and small, into laiye rpa's frame, then laiye rpa's frame will become very bloated, and the difficulty of learning will also increase significantly.
then, the question comes. what should users do if they encounter a problem that the laiye rpa framework cannot directly solve? similar to java or javascript, laiye rpa also provides a plug-in mechanism. if you are good at the universal programming languages on the market, then you can use these programming languages to achieve specific functions to call in laiye rpa.
more interestingly, laiye rpa also supports writing plugins in many different programming languages. including python language, java language, lua language, c# language and c language. you can choose your favorite language within this range, no matter which plugin is written in laiye rpa, there is almost no difference in use.
of course, due to the large differences between different programming languages, the method of writing plug-ins for laiye rpa using different programming languages is also different. this article introduces how to write plug-ins for laiye rpa using python, java, and c#. considering that c language is more difficult to learn, there are few class libraries in lua language. this article will not introduce the plug-in mechanism of these two languages.
in the following description, the file directory is often involved. unless otherwise specified, it refers to the relative path relative to the laiye rpa installation directory. in order to facilitate writing, we use the / symbol as the path separator, rather than the \ symbol used by windows.
it is simplest to write a laiye rpa plug-in in python. you can just use any text editor to write a file with the extension .py (hereinafter referred to as py file), save it in utf-8 format, and place it in the extend/python directory. you can directly call the function defined in this py file in the form of plugin function name.
note that the plug-in name here refers to the part of the file name before the extension .py. for example, if the file name is test.py, the plug-in name is test.
let's look at a complete example:
write plug-in source code. open the extend/python directory, create a test.py file in this directory, and open the test.py file in the notepad and write the following content:
def add (n1, n2): return n1 n2
save the test.py file as utf-8 encoding format, as shown below:
figure 72: python plugin writing
call the plug-in function. open laiye rpa, create a new process, and write the code in the code view:
traceprint test.add (1, 1)
verify whether the plug-in function is correct. running this process, if the results are as follows, it means that the plug-in call is working.
figure 73: python plugin running results
when writing a plug-in in python, in addition to calling the functions of python itself, the plug-in can call some functions of laiye rpa in turn. these functions are called plugin apis.
the calling method of the plugin api is as follows:
write the following code in the python plugin:
import uibot
directly call the plugin api, for example:
def commanderinfo (): return uibot.getcommanderinfo ()
currently available plugin apis in python plugins include:
uibot.isstop()
this function is used to detect whether the current process needs to stop immediately (for example, the user presses the "stop" button). when it needs to stop, it returns true; otherwise, it returns false.
when a plug-in function needs to be executed for a relatively long time, during the execution process, the process cannot be stopped immediately if the user decides to stop the process without executing the plug-in function. therefore, it is recommended that when writing a plug-in, you take into account that the plug-in function has a longer execution time. it is also recommended to periodically call this plug-in api during the function execution to determine whether the process needs to stop. if you want to stop, you should exit the plug-in function immediately.
uibot.getstring(string_path)
this function is used to obtain a certain string of the current language version. the parameter is a string path (explained below), and the return value is the obtained string.
we may use strings in plugins, and some string contents need to be distinguished by language versions. for example, let’s say we need to prompt an error message in the plug-in. this error message should include the chinese version, the english version or other language versions. if the user is using the chinese version of uibot, then the chinese error will be reported; if the user is using the english version of uibot, the english error will be reported.
how can we do this? we can see the two files lang/en-us/extend.json and lang/zh-cn/extend.json in the installation directory of laiye rpa (other language versions also have similar paths, which will not be repeated), indicating plug-ins respectively english and chinese character strings to be used in. you can write the different language versions of the string we want to use to these files, and then use uibot.getstring() in the plug-in to get the required string.
of course, there are many plug-ins for laiye rpa, and there are also many strings in each plug-in. since many strings are placed in a file, how can we ensure that there is no conflict? it is easy to see that this file is in json format, where multiple nested json objects are used to distinguish different strings. when we need to use a string, we only need to fill in the string path in the parameters of uibot.getstring(). the so-called string path refers to the combination of the object where the string is located and the keys of the objects at all levels above, separated by /. for example, uibot.getstring(‘app/prefix’) obtains the character string in the json object whose key is "app" in this file, and the key is "prefix".
uibot.getcommanderinfo()
when the laiye rpa worker is running the process and establishes a connection with the laiye rpa commander, you can get some information of the commander through this api, such as a url. in addition to the official laiye rpa, the plug-in for general users will not use laiye rpa commander, so it is not necessary to use this api.
a simple py file often has limited functions. only through the import statement in the py file to import some other python modules, its functions are more abundant.
in fact, under the lib/site-packages path of the laiye rpa installation directory, a lot of python modules (and python packages) have been preset. (for the definitions and differences of python packages and modules, please refer to the relevant descriptions, which are not explained in this article.) these modules can be used directly in the python plugin. if we need to import other modules in the plugin, one way is to place it under the lib/site-packages path, and another way is to place it under the extend/python/
when writing a plug-in, we recommend putting the modules imported in the plug-in (assuming that these modules are not preset by laiye rpa itself) under the path of extend/python/
in addition, it is worth noting that some py files will import some modules with the extension pyd. these modules are actually dynamic link libraries in binary format. please note that the dynamic link library distinguishes between 32-bit version and 64-bit version. if the laiye rpa you use is a 32-bit version, then these pyd modules should also be 32-bit versions; otherwise, the pyd module should be a 64-bit version. currently, the community version of laiye rpa is a 32-bit version.
for py files, the source code is completely public. what if we want other people to use the python plugin we wrote and don’t want others to see the source code of the plugin?
we only need to call this plugin at least once in laiye rpa creator, and we will see that an extend/python/_ _ pycache_ _ directory has been created. check this directory and there are files that start with the plug-in and end with things like.cpython-37 and the extension.pyc. for example, if our py file is test.py, a file like this will be created automatically: extend/python/ pycache/test.cpython-37.pyc.
rename this file to test.pyc, and put it in the extend/python directory, and delete the original test.py (please back up before deleting). we can still use the test plugin in laiye rpa, and the usage remains unchanged. because its code has been saved in test.pyc in binary format, we only need to send this file to other people to use, and we can avoid being directly read the source code.
of course, test.pyc is not actually encrypted, and it is still possible that some source code will be decompiled. if you want a more thorough encryption, you need to cooperate with other means that will not be discussed in this article.
if n parameters are defined in the function of the python plug-in, then when called in laiye rpa, you can pass in less than n parameters, and the extra parameters will be automatically filled to none. however, no more than n parameters can be passed in.
you can pass the array or dictionary type in laiye rpa as a parameter to the python plug-in, which corresponds to the list or dict type in python. you can also return the list, tuple, or dict types in python to laiye rpa, and the first two are converted to array types and the last one to a dictionary type. regardless of incoming parameters or return values, these composite types are passed by value between the python plugin and laiye rpa, rather than by reference.
an exception can be thrown in the function of the python plugin. the exception may or may not be caught by the python plugin itself. if the python plug-in does not catch the exception, it will be automatically transferred to laiye rpa, where it will be caught. if laiye rpa does not catch the exception, then the process will quit with an error, and the error message will indicate that it is caused by an exception in the python plug-in, which will help troubleshoot the problem.
laiye rpa has a built-in python running environment, so there is no need to install additional python. even if it is installed, laiye rpa will not use the installed python. the current python built into laiye rpa is version 3.7.1.
variables and functions in python are case sensitive, but when using the python plugin in laiye rpa, you can call the functions in a case -insensitive manner. for example, in the previous example, you can write test.add(1,1) in laiye rpa or test.add(1,1) and they share the same effect.
you can use global variables in python, which means you can write variables outside the function. the values of global variables are shared by all functions in the plugin, but different plugins do not share global variables.
it is easy to write laiye rpa plug-ins using python, but python itself is an independent programming language. it is inconvenient to develop and debug using a text editor. therefore, it is recommended to use an integrated development environment, such as visual studio code for python plug-in development.
starting from laiye rpa version 5.0, writing laiye rpa plugins in java language is supported. readers who have used java know that java source code files generally end with a .java extension and need to be compiled into a byte code (byte code) file with the extension .class using jdk (java development kit) before they can run. when running, it is not necessary to install the jdk, so just install the jre (java runtime environment).
due to 和记娱乐博娱188下载 copyright restrictions, there is no built-in jdk in laiye rpa, but there is a built-in version of jre 1.7 released by oracle. therefore, in order to write plug-ins in java, you need to download and install the oracle jdk 1.7 version yourself. there are a lot of information on the download and installation process on the internet, so this article will not discuss it.
in order to provide convenience to write the plug-in for laiye rpa in java language, we have designed an example of the plug-in and put its source code on github, and you can click here to get it. if you are used to using git, you can also pull from this url: .
subsequent content will focus on this example.
according to the specifications of the java language, first we need to design a plug-in name, and then name the source code file
public class javaplugin { }
in order for laiye rpa to use this class normally, this class must be public and cannot be included in any package. classes can define public, private or protected functions, but only public functions can be directly called by laiye rpa. for example, we defined a function called add in the example. this function is public, so we can call it in laiye rpa.
how do we call it? you need to use the javac program in the hands of jdk to compile this source file and enter it on the command line:
javac -encoding utf8 javaplugin.java
of course, the javac program needs to be in the current search path. in addition, the javaplugin.java in the example is utf-8 encoded, and there are chinese characters in it, so you need to add the option -encoding utf8. if there are no chinese characters, this option can be omitted.
if the compilation is successful, it will automatically generate a file named javaplugin.class. put this file in the extend/java directory, and then you can use it like a python plugin. for example, we can open laiye rpa, create a new process, and write code in the code view:
traceprint javaplugin.add(1, 1)
after running this process, if the result is as follows, then the plug-in call is normal.
figure 74: java plug-in results
similar to the python plug-in, in the java plug-in, you can also use the plug-in api, which in turn calls some of the functions of laiye rpa. if you want to call the plugin api, there is need to import any packages. you only need to copy the laiye rpa directory in the plugin example to the directory where the java plugin source code is located when compiling the java plugin.
the plugin apis currently available in the java plugin include:
uibot.api.isstop()
this is used to detect whether the current process needs to stop immediately (for example, the user presses the stop button). when it needs to stop, it returns true; otherwise it returns false.
for the specific function, please refer to the uibot.isstop function used in the python plugin.
uibot.api.getstring(string_path)
this is used to obtain a string in the current language version. in addition, the parameter is a string path (explained below), and the return value is the obtained string.
for its specific function, please refer to the uibot.getstring() function used in the python plugin. in addition, in the plug-in example, we also used this api to obtain the string with the string path of 'excel/savebook', that is, the file named 'savebook' in the json object named 'excel' in the extend.json file string.
the following laiye rpa source code will first call the getstring() function in the java plug-in, and then call uibot.api.getstring() in laiye rpa in turn. you can enter this code in laiye rpa and run it to see what results you can get.
traceprint javaplugin.getstring()
uibot.api.getcommanderinfo()
when laiye rpa worker runs the process and establishes a connection with the laiye rpa commander, you can get some information of commander through this api. unlike laiye rpa official, laiye rpa commander will not be used in the plug-ins of general users, so it is not necessary to use this api.
java is a static programming language; that is, variables need to be defined before use, and the type of variable (integer, floating point, string, etc.) must be specified during the definition. at run time, the variable can only be used as this type. moreover, arrays can usually only contain one type of data.
but this is very different from laiye rpa. the variables of laiye rpa are dynamic types. you do not need to specify the type, you can change the type at runtime, and you can put various types of data in arrays.
therefore, in order to successfully use the java plug-in in laiye rpa, the following requirements must be met:
if the parameters of the java plug-in are integers, floating-point numbers, strings, or boolean types, the parameters passed by laiye rpa must also be of the same type (except for the exceptions described in the following items); otherwise an error will occur
if the parameter of the java plug-in is a floating point number, you can pass in an integer without error. but the converse is not true; that is, if the parameter of the java plug-in is an integer, floating point numbers cannot be passed in
if the parameter of the java plug-in is long, you can pass in an integer less than 2^31 without error. but the opposite is not true. in other words, if the parameter of the java plug-in is an integer (int), you cannot pass in an integer greater than or equal to 2^31
if you need to transfer the dictionary or array type from java to the laiye rpa plug-in, the parameter type in the java plug-in can only use org.json.jsonarray (corresponding array) or org.json.jsonobject (corresponding dictionary)
if you need to transfer the dictionary or array type from the java plug-in to laiye rpa, the return value type in the java plug-in can only use org.json.jsonarray or org.json.jsonobject. laiye rpa will automatically convert the return value of type org.json.jsonarray into an array, and the return value of type org.json.jsonobject into a dictionary
regardless of incoming parameters or return values, these composite types are passed by value between the java plug-in and laiye rpa, rather than by reference
import org.json.*; can be written in the java source code, so that you can directly use the jsonarray or jsonobject type to avoid the org.json prefix. this is how it is written in the plugin example. in addition, the org.json package has been included in the operating environment by laiye rpa, without additional downloading and installation.
in the plug-in example, there is a concat function, which is used to demonstrate how to transfer two arrays from laiye rpa to the java plug-in, and how to return the result of connecting the two arrays to laiye rpa. we recommend reading this section carefully.
similar to python, a simple java file often has limited functions. it has a large set of functions only through the import statement in the source code, which imports other java packages.
we have built-in oracle jre 1.7 in laiye rpa. of course, it also includes the packages that comes with jre, such as com.sun.javafx. in addition, we also built the org.json package to be used in laiye rpa. in addition to the above, other third-party java packages need to be placed in the extend/java directory for normal use. the placement rules are as follows:
if we need to use a class named c in our plugin, we only need to put the c.class file in the extend/java directory
if our plugin needs to use a package named b, which contains a class named c, you can put the c.class file in the extend/java/b directory, or you can package the c.class file to generate the name of the b.jar file which is placed in the extend/java directory
if our plug-in needs to use a package named ab, which contains a class named c and the previous rule’s file, you can put the c.class file in the extend/java/a/b directory, or pack the c.class file and the b directory to generate a file named a.jar and place it in the extend/java directory
the above rules actually follow the rules of class path specified by java. readers who are familiar with the java language should find the above rules to be a review.
the functions in the java plug-in do not support variable parameters or default parameters. when calling, you must pass in the specified number and type of parameters.
an exception can be thrown in the function of the java plug-in. the exception may or may not be caught by the java plug-in itself. if the java plug-in does not catch the exception, it will be automatically transferred to laiye rpa, where it will be caught. if laiye rpa does not catch the exception, then the process will quit with an error, and the error message will indicate that it is caused by an exception in the java plug-in, which will help troubleshoot the problem.
variables and functions in java are case sensitive, but when using the java plug-in in laiye rpa, you can call the functions in a case-insensitive manner. for example, you can write javaplugin.add(1,1) in laiye rpa or javaplugin.add(1,1), and the effect is exactly the same.
when writing a java plug-in, a java class is actually defined, and the public function in the class is called to laiye rpa. this class can have a constructor or member variables, and its initialization will be completed automatically when the process starts running.
oracle jre version 1.7 is built into laiye rpa. you need to download oracle jdk version 1.7 to compile a java plugin. although the versions of jdk and jre are sometimes inconsistent, it can still work. however, in order to reduce the trouble, it is recommended to use the same version. in addition, it is also recommended to use an integrated development environment to develop java plug-ins, such as eclipse or intellij idea.
part of the code of laiye rpa itself is based on microsoft's .net framework and written in c# language. therefore, laiye rpa plug-ins (hereinafter referred to as .net plug-ins) can also be written in c# language. in fact, microsoft's .net framework supports multiple programming languages, including vb.net, c /cli, etc. these programming languages all follow the specifications of the .net framework, and they can all be used to write .net plugins. however, c# is the programming language mainly promoted by microsoft, so this article uses c# as an example, and experienced readers can also port it to other languages in the .net framework. in addition, laiye rpa's support for .net plug-ins is also constantly being upgraded. this article uses laiye rpa version 5.0 as an example. if some examples do not work properly on the old version of laiye rpa, please upgrade laiye rpa.
in order to facilitate you in writing .net plug-ins in c# language, we have designed a plug-in template and put its source code on github. click here to get it. if you are used to using git, you can also pull from this url:.
it is recommended that you write directly on the basis of this template when writing .net plug-ins without starting from scratch. the follow-up content will also focus on the examples in this template.
similar to the java plug-in, the .net plug-in also needs to be compiled into a file with the extension .dll in order to be used by laiye rpa. microsoft's integrated development environment visual studio has both writing and compiling functions, and also provides a free community version, which is the one recommended to download and use. the template we provide is based on the visual studio 2015 version. you can choose this version or a higher version of visual studio, but it is not recommended to use visual studio lower than the 2015 version.
after installing visual studio and downloading our .net template, you can double-click the uibotplugin.sln file. this is a "solution", whose name is a bit deceiving. but it is actually a collection of multiple related files. after opening this solution with visual studio, it contains a lot of content as you can see. the only thing we need to modify is the uibotplugin.cs file. other files, references, properties, etc. can be left untouched. as shown below:
figure 75: .net plugin template
in the uibotplugin.cs file, there is a namespace called uibotplugin, which contains an interface (interface) and a class (class). to avoid confusion, we recommend changing the name of this namespace to the plug-in name. for example, if the final plug-in file is dotnetplugin.dll, then the plug-in name is dotnetplugin, and the name of this namespace should be changed to dotnetplugin.
it can be seen from the template: three functions are declared in the interface, and the implementation of these three functions is written in the class. these three functions are examples. you can delete their declarations and implementations at any time and add your own plug-in functions. but please pay special attention that when adding functions, you should also maintain a similar writing, which needs to be declared in the interface and implemented in the class. otherwise, laiye rpa cannot normally recognize this plug-in function.
we will use the add function from earlier as an example to compile the plugin, and call this function in laiye rpa:
select the "build" menu item in visual studio. after compiling this solution, you will see a directory called release under the plug-in directory, which generates a file called uibotplugin.ddl.
manually rename this file to your plug-in name, and retain the extension of .dll. let's say we rename it to "dotnetplugin.dll".
put this file in the extend/dotnet directory of laiye rpa.
open laiye rpa, create a new process, and write the code in the code view:
traceprint dotnetplugin.add(1, 1)
after running this process, if the result is as follows, then the plug-in call is normal.
figure 76: .net plugin running results
you may have noticed that in the previous examples of the add function in python plug-ins and java plug-ins, laiye rpa returns the same result regardless of which function it calls. however, the internal implementation of different plug-ins is very different. for example, in python language, utf-8 encoding is used to save strings, while in .net, utf-8 is used by default. but laiye rpa has helped you smooth out these differences, so that you do not have to care about these details during use.
similar to the python and java plug-ins, in the .net plug-in, you can also use the plug-in api, which calls part of laiye rpa's functions in turn. if you want to call the plug-in api, you only need to write a plug-in based on our template, without any other settings. the names, parameters and meanings of the plug-in apis that can be used in the .net plug-in are exactly the same as the java plug-in. for example, laiye rpa.api.isstop() can be used to detect whether the current process needs to stop immediately. please refer to the explanation of the plug-in in the java plug-in for more details.
similar to java, c#.net is also a static programming language. variables need to be defined with their types before use. moreover, arrays can usually only contain the same type of data. this is very different from laiye rpa’s dynamic type.
therefore, when writing and using .net plug-ins, the following requirements must be met:
for basic type parameters such as integers, floating-point numbers, strings, and boolean types, laiye rpa does not strictly check the type of the .net plug-in. and even if the conversion is unsuccessful, it will not report an error. therefore, please pay special attention to the type of each parameter when using it to avoid incorrect values being passed in and not found in time.
if you need to transfer the dictionary or array type from laiye rpa to the .net plug-in, the parameter type in the .net plug-in can only use newtonsoft.json.ling.jarray (corresponding to the array) or newtonsoft.json.ling.jobject (corresponding to the dictionary). in the template, since we have imported the class newtonsoft.json.linq, the prefix can be omitted and abbreviated as jarray (corresponding array) or jobject (corresponding dictionary), which is also used in the following simplified writing.
if you need to pass the dictionary or array type from the .net plug-in to laiye rpa, the return value type in the .net plug-in can only use jarray (corresponding array) or jobject (corresponding array). laiye rpa will automatically convert the return value of type jarray into an array and the return value of type jobject into a dictionary.
regardless of incoming parameters or return values, these composite types are passed by value between .net plug-ins and laiye rpa, rather than by reference.
in the plug-in template, there is a concat function as an example to demonstrate how to transfer two arrays from laiye rpa to the .net plug-in, and how to return the result of connecting the two arrays to laiye rpa. we recommend reading this section carefully.
jarray and jobject are not built into the .net framework, but are implemented using open source json.net. when compiling and running, you need to rely on a file called newtonsoft.json.dll. you may have noticed that as long as you put this file in the directory where the plug-in source code is located before compiling, and put this file in the extend/dotnet directory before running, you can compile and use it normally. we have put in newtonsoft.json.dll for you in advance. if your plug-in still needs to rely on other files, just follow this procedure.
the function in the .net plug-in supports default parameters. when calling, if some parameters have default values, you do not need to pass the value, since this parameter will automatically take the default value.
an exception can be thrown in the function of the .net plug-in. the exception may or may not be caught by the .net plug-in. if the .net plug-in does not catch the exception, it will be automatically transferred to laiye rpa, which it will be caught. if laiye rpa does not catch the exception either, then the operation of the process will exit with an error, and the error message will say that there was an exception in the .net file, which will help you troubleshoot the problem.
the variables and functions in .net are case sensitive, but when using the .net plug-in in laiye rpa, you can call the functions in a case-insensitive manner. for example, you can write dotnet.add(1,1) or dotnet.add(1,1), and the effect is exactly the same.