ParaView/Python/Extracting Multiple Blocks

From KitwarePublic
< ParaView
Revision as of 15:58, 23 June 2009 by Berk (talk | contribs) (New page: I had some fun doing this in Python. Here is a script that creates a Python filter for each block and names it with the block name. To run it, you need to select the reader (or any other f...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

I had some fun doing this in Python. Here is a script that creates a Python filter for each block and names it with the block name. To run it, you need to select the reader (or any other filter) and then run this script using the Python Shell under the Tools menu. This requires ParaView version >= 3.7 (June 23, 2009).

Another hint: remember that you can turn on/off the visibility of multiple object by selecting them (using shift+click or control+click) in the pipeline browser and clicking on the visibility icon (the eye) of one of them.

<source lang="python"> from paraview.simple import *

def extract_block(source, outputType, name, di, idx):

  if name:
      pf = ProgrammableFilter(source, registrationName=name)
  else:
      pf = ProgrammableFilter(source)
  pf.OutputDataSetType = outputType
  pf.Script = """

input = self.GetInputDataObject(0, 0) self.GetOutputDataObject(0).ShallowCopy(input.GetBlock(%d))""" % idx

  if outputType == 'vtkImageData' or outputType ==

'vtkStructuredGrid' or outputType == 'vtkRectilinearGrid':

      pf.RequestInformationScript = """

from paraview import util util.SetOutputWholeExtent(self, %r)""" % list(di.GetExtent())

  Show(pf)

source = GetActiveSource() if not source:

  raise RuntimeError, "This macro needs an active pipeline object"

source.UpdatePipeline() cdi = source.GetDataInformation().GetCompositeDataInformation() blocks = cdi.GetNumberOfChildren() for i in range(blocks):

  di = cdi.GetDataInformation(i)
  eb = extract_block(source, di.GetDataClassName(), cdi.GetName(i), di, i)

Hide(source) </source>