How to use/copy python output.

Discuss RoboTask here
Post Reply
DrinStony
Posts: 1
Joined: Fri Sep 23, 2022 1:37 pm

How to use/copy python output.

Post by DrinStony »

I run a script that outputs a two digits number.
How do I use that number in my next actions?
Copy/paste? Or something else?
Tnx
Oleg
Site Admin
Posts: 3010
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to use/copy python output.

Post by Oleg »

You do not need use python STDOUT
You should export necessary values to RoboTask variable
Look at my small example (see below). The script calculates something and export the value
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.
Read here about RoboTask object for Python

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task78"
Hide=INTEGER|0
ID=INTEGER|-1894364826
LogOnAsUser=INTEGER|1
Name=STRING|"Export variable from python"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER

[Actions\Action1]
ActionID=STRING|"A_SCRIPT_PYTHONSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"Python Script"
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
script_0=STRING|"from robotask import *"
script_1=STRING|"# calculate something"
script_10=STRING|"rt = RoboTask()"
script_11=STRING|"rt.set_user_var('MyVariable', str(c))"
script_2=STRING|"a = 23.5"
script_3=STRING|"b = 37.8"
script_5=STRING|"c = a + b"
script_6=STRING|"# output the result to StdOut"
script_7=STRING|"print(c)"
script_9=STRING|"# export the value to RoboTask variable"
script_count=STRING|"13"
script_type=STRING|"0"
search_paths_count=STRING|"0"
use_embedded=STRING|"1"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Show the value from python script"""
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"Show the value from python script"
msg2=STRING|"The value is: {MyVariable}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"

Oleg Yershov
Post Reply