Passing arguments to a python function call

Tecplot's automation language

Python scripts were supported in the alpha version for Legacy 360 (2013). Python inquiries in 2017 should be directed to the PyTecplot Forum.

Moderators: davetaflin, salter, steve, jprenaud, straton, Chris Idso

wandadars
Newbie
Posts: 3
Joined: Tue May 27, 2014 2:48 pm
Location: Florida

Passing arguments to a python function call

Postby wandadars » Thu Jul 28, 2016 10:37 am

Hi,

I'm trying to call a python function from within a Tecplot macrofunction.

The main goal is to call a python function and pass it the loop indices for a nested loop that I have, and have the python script go to a file and retrieve an entry based on those two parameters i.e. value = my_python_script(loop_1_index,loop_2_index)

I'm trying to put something together based on the following forum posts:
http://www.tecplottalk.com/forums/viewtopic.php?t=340
http://tecplottalk.com/forums/viewtopic.php?f=12&t=1097


The relevant part of my macrofunction code is:

Code: Select all

#Get the mean value
$!EXTENDEDCOMMAND
  COMMANDPROCESSORID= "Python Utility"
  COMMAND='MODIFYPATH FOLDER' = "|PythonPath|"

$!EXTENDEDCOMMAND
  COMMANDPROCESSORID= "Python Utility"
  COMMAND='RUNPYFUNCTION MODULE="compute_fluctuation" FUNCTION="compute_fluctuation_module" ARGUMENTS="|VarName|,|TimeLoopIndex|,|LOOP|"'



My Python script looks like:

Code: Select all

def compute_fluctuation_module(var_name,loop_index,slice_index)
   import TecUtils
   import TecVals


   #Locate mean value from users inputs
   input_file_name = var_name + "_"+loop_index+".txt"
   
   line_count = 1
   with open(input_file_name,'r') as f:
      for Line in f:
         if line_count == slice_index):
            mean_value = f.readline()
         else:
            line_count = line_count + 1
            
            
            {p_prime} = {p} - 100000'
            
            
   equation_string = "{"+var_name+"_prime} = "+"{"+var_name+"} - "+mean_value
   TecUtil.DataAlter(equation_string)
   
   

   return


Tecplot complains that: COMMAND='RUNPYFUNCTION MODULE="compute_fluctuation" FUNCTION="compute_fluctuation_module" ARGUMENTS="|VarName|,|TimeLoopIndex|,|LOOP|"' is not a valid command.


What would be the best way to structure a call to a python script from within my macrofunction such that I can pass it parameters? I'm also not 100% sure that I structured the RUNPYFUNCTION MODULE command correctly. The double and single quotes that are used in the examples shown in the forum posts that were linked to earlier are confusing i.e. I don't always see a set of matching open and close quotations around the commands.

Thank you,
Chris Neal

teddy26
Newbie
Posts: 1
Joined: Sun Jan 06, 2019 12:46 am
Location: India

Re: Passing arguments to a python function call

Postby teddy26 » Sun Jan 06, 2019 1:34 am

Hello,

If I correctly speaking python uses mechanism of call by object sometimes we call it call by sharing in which we pass argument like integers,strings,function etc.What i'm saying this is correct or not??I think error is generate just because of coding which isn't in correct way or the way which we pass argument.
I think if you are not satisfied with me then I'm not getting your point correctly.
Please check by google.
Thanks...

Python Compiler


Return to “Tecplot Macro Language”

Who is online

Users browsing this forum: No registered users and 8 guests