Python: Toggling zones by regular expressions
This is what I came up with, and it can be called from the Quick Macro Panel:
import TecUtilAs mentioned last time, we expose only those functions prefaced by TP_, thus here are our two wrapper functions:
import TecVals
import re
import string
#
# This function toggles the named zones on or off depending on the
# pattern provided. If you specify "all," it applies to all zones.
#
def toggle_zones(zonename, onoff):
if onoff == "off":
setto = TecVals.AssignOp_MinusEquals
else:
setto = TecVals.AssignOp_PlusEquals
n=CountFieldmaps()
#
# count through fieldmaps
#
Results = []
tmp = []
for i in xrange(1,n+1):
Results = TecUtil.ZoneGetName(i)
if (re.compile(zonename).search(Results[1],1) or zonename == "all"):
tmp.extend([i])
TecUtil.ZoneSetActive(tmp, setto)
return
#
# The ADK is unforgiving about some operations. Thus, we check if a dataset
# is available first, then we return the number of fieldmaps. Note that we use
# fieldmaps instead of zones because the dataset could be transient. If it is,
# we will turn off parts across all timesteps.
#
def CountFieldmaps():
if TecUtil.DataSetIsAvailable():
return (TecUtil.FieldMapGetCount())
else:
debugm("There is no dataset loaded.")
return -1
return
def TP_zones_off(zone_name_pattern):
return toggle_zones(zone_name_pattern,"off")
def TP_zones_on(zone_name_pattern):
return toggle_zones(zone_name_pattern,"on")
0 TrackBacks
Listed below are links to blogs that reference this entry: Python: Toggling zones by regular expressions.
TrackBack URL for this entry: http://www.tecplottalk.com/b/mt-tb.cgi/5

Leave a comment