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

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


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:

The relevant part of my macrofunction code is:

Code: Select all

#Get the mean value

  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()
            line_count = line_count + 1
            {p_prime} = {p} - 100000'
   equation_string = "{"+var_name+"_prime} = "+"{"+var_name+"} - "+mean_value


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

Return to “Tecplot Macro Language”

Who is online

Users browsing this forum: No registered users and 0 guests