Home > Uncategorized > Reload files in Paraview

Reload files in Paraview

Here is a macro to reload files in Paraview. To use it go to Macro, Add new macro....

import re
import os

files = None
s = GetActiveSource()
    files = s.FileName
except AttributeError:
    print "Not a file source"

if files and len(files) == 1:
    # one time step
    s.FileName = [files[0]]
elif files:
    # multiple time steps
    reg = re.compile(r"(.+[^0-9])([0-9]+)\.(.+)")
    roots = set()
    exts = set()
    for f in files:
       m = reg.match(f)
       if m:
           roots = None
    if roots and len(roots) == 1 and len(exts) == 1:
        root = roots.pop()
        ext = exts.pop()
        basedir = os.path.dirname(root)
        basename = os.path.basename(root)
        unsorted_l = []
        for p in os.listdir(basedir):
            m = reg.match(p)
            if m and basename == m.group(1):
                unsorted_l.append((int(m.group(2)), os.path.join(basedir, p)))
        s.FileName = [p for i, p in sorted(unsorted_l)]
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: