Include python file in a macro file

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

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Include python file in a macro file

Postby gdeshmukh11 » Wed Jun 09, 2010 7:10 am

hi..

i want to include/run a python file inside another macro file. is it possible this way or other way round?
I have recorded 1 macro. inside this macro i have 1 equation which needs some values from different files. I am thinking of writing a python script which will fetch these values from different files and will provide it to the equation in the macro.

will it be posible? :roll:

Chris Idso
Jedi Master
Posts: 249
Joined: Mon Jan 15, 2007 10:07 am
Location: Bellevue, WA
Contact:

Re: Include python file in a macro file

Postby Chris Idso » Wed Jun 09, 2010 9:21 am

Hello,

Yes. This is possible. There is a macro command you can use to call a python script:

$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME="<filename>"

where the <filename> is the name of the python module to play, and it does not include the path to the module. Instead, the file must reside in a directory included in definition of your PYTHONPATH environment variable.

You can add a path to your PYTHONPATH environment variable with a macro command too, as follows:

$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'MODIFYPATH FOLDER="<filepath>"
Chris


Christopher Idso

Tech Support Lead
Tecplot, Inc

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Thu Jun 10, 2010 6:37 am

my old code..

#!MC 1200
# Created by Tecplot 360 build 12.0.0.3454
$!VarSet |MFBD| = '/home/gdeshmukh/t106a_testsuite/Re700/input'
$!NEWLAYOUT
$!READDATASET '"|MFBD|/surf_blk0_lower.dat" "|MFBD|/surf_blk1_lower.dat" "|MFBD|/surf_blk2_lower.dat" '
READDATAOPTION = NEW
RESETSTYLE = YES
INCLUDETEXT = NO
INCLUDEGEOM = NO
INCLUDECUSTOMLABELS = NO
VARLOADMODE = BYNAME
ASSIGNSTRANDIDS = YES
INITIALPLOTTYPE = XYLINE
VARNAMELIST = '"t" "x" "y" "z" "BLK" "idxEdge" "Mode" "dUds" "Tu" "uE" "rhoE" "rhoW" "y+" "tauW" "tauMax" "p" "Mis" "Medge" "ReTh" "ReThS" "d" "d1" "d2" "H12" "maxEV" "maxTu" "transFP" "transFD" "thermConduct" "heatFlux" "heatCoeff" "TWall" "TEdge" "mueLamW" "uWall" "vWall" "wWall" "sepAngle" "deflAngle" "wakeAngle" "H12inc" "ReThCF" "ReThSCF" "ReThCFwmx" "dummy1" "dummy2"'
$!ALTERDATA
EQUATION = '{cp}=({p} -522885)/(67013.14-522885)'
$!ALTERDATA
EQUATION = '{cp}=({p} -522885)/(67013.14-522885)'
$!LINEMAP [1] ASSIGN{XAXISVAR = 2}
$!LINEMAP [1] ASSIGN{YAXISVAR = 47}
$!DELETELINEMAPS [2-4]
$!DELETELINEMAPS [2-42]
$!CREATELINEMAP
$!DUPLICATELINEMAP
SOURCEMAP = 1
DESTINATIONMAP = 2
$!LINEMAP [2] NAME = '&DV&'
$!CREATELINEMAP
$!DUPLICATELINEMAP
SOURCEMAP = 1
DESTINATIONMAP = 3
$!LINEMAP [3] NAME = '&DV&'
$!ACTIVELINEMAPS += [2]
$!ACTIVELINEMAPS += [3]
$!LINEMAP [3] ASSIGN{ZONE = 3}
$!LINEMAP [2] ASSIGN{ZONE = 2}
$!VIEW DATAFIT
$!RemoveVar |MFBD|

now i want to write a python code which gives 'EQUATION = {cp}=...'

i tried following..to include python code
#!MC 1200
# Created by Tecplot 360 build 12.0.0.3454
$!VarSet |MFBD| = '/home/gdeshmukh/t106a_testsuite/Re700/input'
$!NEWLAYOUT
$!READDATASET '"|MFBD|/surf_blk0_lower.dat" "|MFBD|/surf_blk1_lower.dat" "|MFBD|/surf_blk2_lower.dat" '
READDATAOPTION = NEW
RESETSTYLE = YES
INCLUDETEXT = NO
INCLUDEGEOM = NO
INCLUDECUSTOMLABELS = NO
VARLOADMODE = BYNAME
ASSIGNSTRANDIDS = YES
INITIALPLOTTYPE = XYLINE
VARNAMELIST = '"t" "x" "y" "z" "BLK" "idxEdge" "Mode" "dUds" "Tu" "uE" "rhoE" "rhoW" "y+" "tauW" "tauMax" "p" "Mis" "Medge" "ReTh" "ReThS" "d" "d1" "d2" "H12" "maxEV" "maxTu" "transFP" "transFD" "thermConduct" "heatFlux" "heatCoeff" "TWall" "TEdge" "mueLamW" "uWall" "vWall" "wWall" "sepAngle" "deflAngle" "wakeAngle" "H12inc" "ReThCF" "ReThSCF" "ReThCFwmx" "dummy1" "dummy2"'
$!ALTERDATA
$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME' ="macropythoneqn.py"
$!LINEMAP [1] ASSIGN{XAXISVAR = 2}
$!LINEMAP [1] ASSIGN{YAXISVAR = 47}
$!DELETELINEMAPS [2-4]
$!DELETELINEMAPS [2-42]
$!CREATELINEMAP
$!DUPLICATELINEMAP
SOURCEMAP = 1
DESTINATIONMAP = 2
$!LINEMAP [2] NAME = '&DV&'
$!CREATELINEMAP
$!DUPLICATELINEMAP
SOURCEMAP = 1
DESTINATIONMAP = 3
$!LINEMAP [3] NAME = '&DV&'
$!ACTIVELINEMAPS += [2]
$!ACTIVELINEMAPS += [3]
$!LINEMAP [3] ASSIGN{ZONE = 3}
$!LINEMAP [2] ASSIGN{ZONE = 2}
$!VIEW DATAFIT
$!RemoveVar |MFBD|


i wrote python code macropythoneqn.py as
import os

EQUATION = '{cp}=({p} -522885)/(67013.14-522885)'

but i m getting an error if i run the recorded macro...
:roll:

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Fri Jun 11, 2010 5:40 am

error is only in the following part of the macro...

$!ALTERDATA
$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME' ="macropythoneqn.py"

Chris Idso
Jedi Master
Posts: 249
Joined: Mon Jan 15, 2007 10:07 am
Location: Bellevue, WA
Contact:

Re: Include python file in a macro file

Postby Chris Idso » Fri Jun 11, 2010 9:10 am

Hello,

Python is a scripting language, but it is nothing like Tecplot's macro language, so just using "EQUATION = '{cp}=({p} -522885)/(67013.14-522885)' " will not work. In order to have your python script interact with Tecplot, it needs to call functions that are similar to the TecUtil functions that are used in our ADK (Addon Developers Kit). In fact, the Reference for our ADK contains the Python equivalent of the TecUtil functions, and the Python syntax too.

Our ADK Reference is found by going to your Tecplot folder. From that folder go to Doc/Tecpot/adkrm/. In that folder find and then click on the index.html file, ad this will start the Reference Guide. The just find the TecUtil function list and then check out the TecUtilDataAlter() function.
Chris





Christopher Idso



Tech Support Lead

Tecplot, Inc

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Tue Jun 22, 2010 6:42 am

how can I combine following to sets??

1)$!ALTERDATA
EQUATION = '{cp}=({p} -522885)/(67013.14-522885)'

2)$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME' ="macropythoneqn.py


my try was...

$!ALTERDATA
$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME'= "macropythoneqn.py"

but its not working..with error as "missing EQUATION==suboptions in $!ALTERDATA command"

and,
my macropythoneqn.py is now,
"""
import os


EQUATION = os.getenv("EQUATION")

Results = TecUtil.DataAlter('{cp}=({p} -522885)/(67013.14-522885)',NULL,1,0, 0,1, 0,0,1,0,0, FieldDataType_Invalid)

"""



:roll:

Chris Idso
Jedi Master
Posts: 249
Joined: Mon Jan 15, 2007 10:07 am
Location: Bellevue, WA
Contact:

Re: Include python file in a macro file

Postby Chris Idso » Tue Jun 22, 2010 9:25 am

Hello,

This:

$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME' ="macropythoneqn.py


should work by itself. You would not need the $!ALTERDATA command because the python script you are using is already altering the data. So all you need to is call the python script from the macro, as shown above - without the $!ALTERDATA command.
Chris





Christopher Idso



Tech Support Lead

Tecplot, Inc

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Wed Jun 23, 2010 6:50 am

$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME' = "macropythoneqn.py"


getting error in the above part as "unknown command or subcommand"

Chris Idso
Jedi Master
Posts: 249
Joined: Mon Jan 15, 2007 10:07 am
Location: Bellevue, WA
Contact:

Re: Include python file in a macro file

Postby Chris Idso » Wed Jun 23, 2010 7:59 am

Hello,

We looked more closely at your command which calls the python script. This:

$!EXTENDEDCOMMAND
COMMANDPROCESSORID = "Python Utility"
COMMAND = 'LOADPVFILE NAME' = "macropythoneqn.py"

will not work because

COMMAND = 'LOADPVFILE NAME' = "macropythoneqn.py" is not valid. it needs to be:

COMMAND = 'LOADPYFILE NAME' = "macropythoneqn.py"

instead. Please make this change and let us know if this works for you.
Chris





Christopher Idso



Tech Support Lead

Tecplot, Inc

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Thu Jun 24, 2010 6:12 am

still getting the same error.. :roll:

Chris Idso
Jedi Master
Posts: 249
Joined: Mon Jan 15, 2007 10:07 am
Location: Bellevue, WA
Contact:

Re: Include python file in a macro file

Postby Chris Idso » Thu Jun 24, 2010 1:08 pm

Hi,

One more thing we noticed:

The last parameter in the TecUtil.DataAlter statement in your macro needs to have 'TecVals.' in front of it or the python script does not know what it is. PLease make this change and let us know if it helps!

Your description of your macro and python script is not clear as to just what your python script is reading and then placing within the ALTERDATA EQUATION statement. It looks like it might be reading the entire equation but this is not what your initial emails suggested.

Would you please provide more details about what you are trying to do?
Chris





Christopher Idso



Tech Support Lead

Tecplot, Inc

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Mon Jun 28, 2010 2:51 am

what I am trying to do is, i have written a python script which will have one equation mentioned. now I have called this python script in my macro(which plots graph of this equation).

the basic idea is to automate the process of plotting graph. so i recorded a macro by manually plotting that graph.

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Mon Jun 28, 2010 5:03 am

or in other words, instead of directly writing equation in macro,under ALTERDATA command, I have written a pythonscript which has that equation.

I even tried putting 'Tecvals.' but getting same error as unknown command or subcommand...

Chris Idso
Jedi Master
Posts: 249
Joined: Mon Jan 15, 2007 10:07 am
Location: Bellevue, WA
Contact:

Re: Include python file in a macro file

Postby Chris Idso » Mon Jun 28, 2010 9:16 am

Thanks. In order for Tecplot to play your python script, the python script (not the macro) needs to be in a directory/folder specified under Tecplot's Scripting/Configure Python Search Path dialog. If the folder where the python script is, does not apprear in the list in the above mentioned dialog then the macro will not be able to call the python script.

Please make sure that the Scripting/Configure Python Search Path dialog contains the path to the python script. If you still get that same error message, please let us know.
Chris





Christopher Idso



Tech Support Lead

Tecplot, Inc

gdeshmukh11
Experienced user
Posts: 10
Joined: Wed Jun 09, 2010 7:04 am
Location: braunschweig
Contact:

Re: Include python file in a macro file

Postby gdeshmukh11 » Mon Jun 28, 2010 9:56 am

yes..i had already included the path of python file...and its in same folder..
i am not sure why is this "unknown command "error


Return to “Tecplot Macro Language”

Who is online

Users browsing this forum: No registered users and 1 guest