top of page

Code Snippet: Houdini pythonModule common functions

Ellie Ansell

Hou.phm() functions for simple tasks, such as returning all files matching a regex from a path. This was used for a lookdev OTL, to grab all HDRIs on shows in given folders.


import os
import re
import sys

import imp


'''
Author: Ellie Ansell
Date edited: 09/04/20
Desc: Simple functions to parse data.
'''

def buildMenuStringList(names):
    """ Duplicates each element in a list of strings.
            For example, ["walk", "run"] becomes ["walk", "walk", "run", "run"]
    """
    return [name for pair in zip(names, names) for name in pair]

def findFiles(path="", re_pattern=".*"):
    """Get a list of the files from a directory matching a given regex.
    """

    if not os.path.exists(path):
            return [""]

    files = []
    for root, ds, fs in os.walk(path):
            for f in fs:
                    if re.match(re_pattern, f) and not f.startswith("."):
                            files.append(f)

    return files or [""]

def findDirs(path="", re_pattern=".*"):
    """Get a list of the files from a directory matching a given regex.
    """
    if not os.path.exists(path):
            return [""]

    files = []

    for f in os.listdir(path):
            if re.match(re_pattern, f) and not f.startswith("."):
                    files.append(f)

    return files or [""]


16 views0 comments

Recent Posts

See All

Comments


  • LinkedIn // Professional Bio
  • Facebook // ellieansellart page
  • Instagram // Informal fun
  • Vimeo

© 2020 by Ellie Ansell

Happily created using Wix.com

bottom of page