Transferring of variables between Python and IDEAScript

9 posts / 0 new
Last post
BVisser
Offline
Joined: 09/18/2020 - 13:47
Transferring of variables between Python and IDEAScript

 
Does anyone know if it is possible to send variables generated in a python script to be used in an IDEAScript? I've got an existing Python script that converts an XML-file into a CSV-file using the pandas module that is called from an IDEAScript using .runpython module in IDEA10.4. However there are also several built-in checks to ensure the completeness and accuracy of the information as well as the location where the file is saved which is stored in variables within the Python script. Is it possible to send these variables with their values to the IDEAScript that calls the Python script to perform these checks within IDEA? Or is this not possible and should I export these values in a textfile and then import this new file into IDEA to use the values of the variables? 
 
 
 
 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Your only option is the Client.RunIDEAScriptRV.  It only allows for 4 variables.  If you need more then you will have to transfer it through a text file. Below is from the language browser.

Client.RunIDEAScriptRV

Run another IDEAScript macro and return four variables to the caller. In order for values to be returned, the called macro must assign the values back to the global constants arg1, arg2, arg3, and arg4, respectively.

Syntax

Client.RunIDEAScriptRV(scriptName As String, arg1 As Variant, arg2 As Variant, arg3 As Variant, arg4 As Variant )

Parameters

[in] scriptName

The macro to be executed.

[in/out] arg1

First parameter, which is also used as a return value.

[in/out] arg2

Second parameter, which is also used as a return value.

[in/out] arg3

Third parameter, which is also used as a return value.

[in/out] arg4

Fourth parameter, which is also used as a return value.

Return Value

Variant

Remarks

Control always returns to the next step of the calling macro when the called macro finishes executing.

If the full path of the file is not specified and only the file name is specified, IDEA limits its search to the root folder of the active project.

If the macro resides in a sub-folder in the active project, you must specify the sub-folder name. For example, Client.RunIDEAScriptEX "Temp\MyScript.ISS", "Hello", "", "", "".

Type

None

Example

Sub Main

' Create input values for an IDEAScript macro.

Arg1 = "Hello"

Arg2 = "Goodbye"

Arg3 = "Blue"

Arg4 = "Green"

' Start another IDEAScript macro.

Client.RunIDEAScriptRV "MyScript.ISS", Arg1, Arg2, Arg3, Arg4

' Display the return values.

MsgBox "The return values are: " & Chr(13) & _

Arg1 & Chr(13) & Arg2 & Chr(13) & _

Arg3 & Chr(13) & Arg4

End Sub

BVisser
Offline
Joined: 09/18/2020 - 13:47

Hi Brian, Thank you for the quick response. I will use a text file then. Thanks for all of the effort you put in this site, it is amazing and greatly appreciated.

jsandoval
Offline
Joined: 03/01/2021 - 10:48

Hello,
I have a similar doubt.  I need to send a variable to python but I'm not sure how. I think that I can do it by using  Client.RunPythonEx but I don't know how to use it or whether there is a code that I need to write in python to accept the variable from IDEA.
Can anyone help me with this?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi jsandoval,

When you install IDEA there is some sample code on exactly how to do this.  If you look in your sample folder under macros: C:\Users\user.name\Documents\My IDEA Documents\IDEA Projects\Samples\Macros.ILB you will see the following files:

ShowMedian.iss and ShowMedian.py

The ShowMedian.iss calls the ShowMedian.py and sends several items to the python script for use by the script.  Hopefully this will make it clear on how to do this, if not come back and let me know.

Good luck.

jsandoval
Offline
Joined: 03/01/2021 - 10:48

Hi Bryant, thank you for the quick response.
 
I've been trying using the function with the example you told me but I still can't make it to work. What I want to do is to declare a variable in IDEA, and then pass that variable to Python to make something with it. But python give me an error because the variable is not declared, wich means that Client.RunPythonEx is not working properly. Could you please tell me what is wrong with my code? I know it must be something silly but I can't figure it out.
 
Sub Main
    Dim test As String
    Dim data(0) As Variant
    test = "This is a test"
    data(0) = test
    Client.RunPythonEx "D:\jsandoval\Downloads\String.py", data
End Sub

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi jsandoval, just to let you know I haven't forgetten this request.  I am hoping to put together a quick video on how this is done.  

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi jsandoval, I finally found some time to make the video, you can find it here - https://youtu.be/M71sjs0KpWY

jsandoval
Offline
Joined: 03/01/2021 - 10:48

Thanks Brian, this video helped me a lot!!