[Paraview] DumpTool.py

Robert Maynard RobertJMaynard at gmail.com
Wed Sep 5 15:10:43 EDT 2007


I know that I found the original dump tool really great tool to have around
when working in paraview. Unfortunately it seems that recently it was
broken, and I have seen a working copy posted again. So I quickly wrote up
this script here that does the basics of what DumpTool did. Please use and
improve it.

#basic dump, Robert Maynard MIRARCO
from paraview.servermanager import *
import sys
import string

class Dump:
  def __init__(self):
    '''the proxies that we want to dump'''
    self.proxies  = ['sources','representations']

  def allToPython(self, fileName=None):
    if fileName:
     stdoutOrig = sys.stdout
     file = open( fileName, 'w')
     sys.stdout = file

    self.__header()
    for proxyGroup in self.proxies:
      for proxy in (self.__getProperties(proxyGroup)):
        print ProxyStorage( proxy[0], proxy[1], proxyGroup, proxy[2]
)
    self.__footer()

    if fileName:
     sys.stdout = stdoutOrig
     file.close()


  #private methods
  def __header(self):
    print '#!/usr/bin/env python'
    print 'from paraview.servermanager import *'
    print 'view = servermanager.GetRenderView()'

  def __footer(self):
    print 'view.StillRender()'

  def __getProperties(self, proxyName):
    #get all the data needed in a view here
    proxy = self.__getProxiesInGroup(proxyName)
    totalProperties = list()
    if (proxyName == self.proxies[1]):
      sourceNames = self.__buildSourceNames(proxy)
      for sname,name in zip(sourceNames,proxy):
        xmlName = proxy[name].GetXMLName()
        totalProperties.append( (sname, xmlName,
self.__getPropertyValues(proxy,name) ) )
    else:
      for name in proxy:
        xmlName = proxy[name].GetXMLName()
        totalProperties.append( (name, xmlName,
self.__getPropertyValues(proxy,name) ) )
    return totalProperties

  def __getPropertyValues(self,proxy, name):
    properties = list()
    for property in proxy[name]:
      name = property.Proxy.GetPropertyName(property.SMProperty)
      try:
        value = property.GetData()
        properties.append( (name,value) )
      except AttributeError:
        pass
    return properties

  def __getProxiesInGroup(self,name):
    pxm = servermanager.ProxyManager()
    proxy = pxm.GetProxiesInGroup(name)
    return proxy

  def __buildSourceNames(self, proxy):
    #builds all the source names for each display, by using the
    #dump tool proxyLabel method
    sourceNames = list()
    for key in proxy.keys():
      inputValue = proxy[key].Input
      sourceNames.append(self.__proxyLabel(inputValue[0]))
    return sourceNames

  def __proxyLabel( self, outputPort ):
    """Returns the given proxy's PV displayed name. Much thanks to the
DumpTool author"""
    pxm = servermanager.ProxyManager()
    proxy = outputPort.Proxy
    proxyGroup = pxm.GetProxiesInGroup(self.proxies[0])
    for name in proxyGroup:
      if (proxyGroup[name] == proxy):
        return name
    return None

class ProxyStorage:
  def __init__(self, name, xmlName,  proxy, propertyRaw):
      self.name = name
      self.xmlName = xmlName
      self.proxyGroup = proxy
      self.property = PropertyStorage(propertyRaw)

  def __repr__(self):
      """Returns a user-friendly representation string."""
      from cStringIO import StringIO
      name = self.name
      propNames = self.property.name
      propValues = self.property.value
      file_str = StringIO()

      if (propNames[0] == 'Input'):
        name = self.name+'Representation'
        file_str.write(name+' =
servermanager.CreateRepresentation('+self.name+',
view, registrationGroup=\''+self.proxyGroup+'\')\n'
)
        propNames.pop(0)
        propValues.pop(0)
      else:
        file_str.write(name+' = servermanager.sources.'+
self.xmlName+'(registrationGroup=\''+
self.proxyGroup +'\', registrationName=\'' + name + '\')\n'
)
      for n,v in zip(propNames,propValues):
        file_str.write(name+'.'+str(n)+' = ')
        try:
          v = str(v)
        except TypeError:
          try:
            v = map(str,v)
            v = string.join(v,',')
          except TypeError:
            pass
          else:
            file_str.write(v)
        else:
          file_str.write(v)
        file_str.write('\n')

      return file_str.getvalue()

class PropertyStorage:
    def __init__(self, items):
      self.name = list()
      self.value = list()
      self.__parse(items)

    def __parse(self,items):
      for parts in items:
        propName = parts[0]
        value = parts[1]
        if isinstance(value, OutputPort):
          value = value.Proxy
        if (value != ''):
          self.name.append(propName)
          self.value.append(value)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/paraview/attachments/20070905/41190db7/attachment.htm


More information about the ParaView mailing list