April 2008 Archives

zoneselect.jpg A customer modeling molecules wanted to toggle on/off zones representing chemical elements.  We have a pattern matching tool in the Zone Style dialog -- see diagram at right -- but each use is about four clicks.  Would there be an easier way to toggle these on and off?

This is what I came up with, and it can be called from the Quick Macro Panel:

import TecUtil
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

As mentioned last time, we expose only those functions prefaced by TP_, thus here are our two wrapper functions:

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")




About this Archive

This page is an archive of entries from April 2008 listed from newest to oldest.

January 2008 is the previous archive.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.01