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.
<br><br>#basic dump, Robert Maynard MIRARCO<br>from paraview.servermanager import *<br>import sys<br>import string<br><br>class Dump:<br> def __init__(self):<br> '''the proxies that we want to dump'''
<br> self.proxies = ['sources','representations']<br> <br> def allToPython(self, fileName=None): <br> if fileName:<br> stdoutOrig = sys.stdout<br> file = open( fileName, 'w')<br>
sys.stdout = file<br> <br> self.__header()<br> for proxyGroup in self.proxies: <br> for proxy in (self.__getProperties(proxyGroup)):<br> print ProxyStorage( proxy[0], proxy[1], proxyGroup, proxy[2] )
<br> self.__footer()<br> <br> if fileName:<br> sys.stdout = stdoutOrig<br> file.close()<br> <br> <br> #private methods <br> def __header(self):<br> print '#!/usr/bin/env python'
<br> print 'from paraview.servermanager import *'<br> print 'view = servermanager.GetRenderView()'<br> <br> def __footer(self):<br> print 'view.StillRender()'<br> <br> def __getProperties(self, proxyName):
<br> #get all the data needed in a view here<br> proxy = self.__getProxiesInGroup(proxyName)<br> totalProperties = list() <br> if (proxyName == self.proxies[1]): <br> sourceNames = self.__buildSourceNames(proxy)
<br> for sname,name in zip(sourceNames,proxy): <br> xmlName = proxy[name].GetXMLName() <br> totalProperties.append( (sname, xmlName, self.__getPropertyValues(proxy,name) ) ) <br> else:<br> for name in proxy:
<br> xmlName = proxy[name].GetXMLName() <br> totalProperties.append( (name, xmlName, self.__getPropertyValues(proxy,name) ) ) <br> return totalProperties<br> <br> def __getPropertyValues(self,proxy, name):
<br> properties = list() <br> for property in proxy[name]: <br> name = property.Proxy.GetPropertyName(property.SMProperty) <br> try: <br> value =
property.GetData() <br> properties.append( (name,value) ) <br> except AttributeError:<br> pass<br> return properties<br> <br> def __getProxiesInGroup(self,name):
<br> pxm = servermanager.ProxyManager()<br> proxy = pxm.GetProxiesInGroup(name) <br> return proxy <br><br> def __buildSourceNames(self, proxy):<br> #builds all the source names for each display, by using the
<br> #dump tool proxyLabel method <br> sourceNames = list()<br> for key in proxy.keys():<br> inputValue = proxy[key].Input <br> sourceNames.append(self.__proxyLabel(inputValue[0]))
<br> return sourceNames<br> <br> def __proxyLabel( self, outputPort ):<br> """Returns the given proxy's PV displayed name. Much thanks to the DumpTool author""" <br> pxm =
servermanager.ProxyManager()<br> proxy = outputPort.Proxy<br> proxyGroup = pxm.GetProxiesInGroup(self.proxies[0])<br> for name in proxyGroup:<br> if (proxyGroup[name] == proxy):<br> return name<br> return None
<br><br>class ProxyStorage:<br> def __init__(self, name, xmlName, proxy, propertyRaw): <br> <a href="http://self.name">self.name</a> = name<br> self.xmlName = xmlName<br> self.proxyGroup = proxy <br>
self.property = PropertyStorage(propertyRaw)<br> <br> def __repr__(self):<br> """Returns a user-friendly representation string."""<br> from cStringIO import StringIO
<br> name = <a href="http://self.name">self.name</a><br> propNames = <a href="http://self.property.name">self.property.name</a><br> propValues = self.property.value <br> file_str = StringIO()<br>
<br> if (propNames[0] == 'Input'):<br> name = self.name+'Representation'<br> file_str.write(name+' = servermanager.CreateRepresentation('+self.name+', view, registrationGroup=\''+self.proxyGroup+'\')\n' )
<br> propNames.pop(0)<br> propValues.pop(0) <br> else:<br> file_str.write(name+' = servermanager.sources.'+ self.xmlName +'(registrationGroup=\''+ self.proxyGroup +'\', registrationName=\'' + name + '\')\n' )
<br> for n,v in zip(propNames,propValues): <br> file_str.write(name+'.'+str(n)+' = ')<br> try: <br> v = str(v) <br> except TypeError:<br> try:
<br> v = map(str,v)<br> v = string.join(v,',') <br> except TypeError:<br> pass <br> else:<br> file_str.write(v)<br> else:
<br> file_str.write(v)<br> file_str.write('\n')<br> <br> return file_str.getvalue()<br> <br>class PropertyStorage:<br> def __init__(self, items):<br> <a href="http://self.name">
self.name</a> = list()<br> self.value = list()<br> self.__parse(items)<br> <br> def __parse(self,items): <br> for parts in items: <br> propName = parts[0]<br> value = parts[1]
<br> if isinstance(value, OutputPort): <br> value = value.Proxy <br> if (value != ''): <br> self.name.append(propName)<br> self.value.append(value)
<br>