To get the global registry, use:
reg = pdg.TypeRegistry.types()
Methods ¶
Static methods ¶
findFile(file_name)
→ str
Static method
Finds a file on the PDG search path and returns the absolute path to that file.
If no file is found, the method returns None.
globFiles(extension, subdirectory, full_path=False)
→ list
of str
Static method
Finds all files on the PDG search path that have the specified file extension
and are found in sudirectory
. If full_path
is True
the function returns absolute paths, otherwise it only returns the file names.
If no file is found, the list is empty.
globPythonModules(unique=True, full_path=False)
→ list
of str
Static method
Returns the list of all Python modules on the PDG custom type search path and returns the list of module names. These are Python modules found in $HOUDINI_PDG_DIR/types
.
If unique
is set to True
, then only unique module names are returned even if multiple modules with the same name are found at different locations on the search path. Python will only be able to import one of those modules based on which one appears first in the search path order. You can set unique
to False
in order to debug such issues.
If full_path
is True
the results are returned as absolute paths.
moduleSkipList()
→ list
of str
Returns the list of file and directory names to skip when importing PDG Python module. This list is defined using the HOUDINI_PDG_TYPE_SKIPLIST environment variable.
searchPath()
→ list
of str
Static method
Returns the search path for PDG node types and templates.
types()
→ pdg.TypeRegistry
Static method
Returns the global type registry instance.
Instance methods ¶
addExtensionTag(extension, tag)
Adds a mapping from file extension to a file tag.
addParentType(type, type_name)
Marks the specified types as parents/convertible for the specified type
. The type
should be a pdg.BaseType instance, and type_name
is a str
name for an existing type.
addParentTypes(type, type_names)
Marks the specified types as parents/convertible for the specified type
. The type
should be a pdg.BaseType instance, and type_names
is a list
of str
type names.
addTag(tag)
Adds a tag without a corresponding file extension. The tag is added to the global list of file tags, but isn’t added to any file extension → tag mappings.
addTagViewer(tag, viewer, multiviewer=False)
Creates a mapping between the specified file tag and the viewer application name. For example, mplay
or gplay
. The application is used when opening output files with the tag from the work item info panel. If multiviewer
is set to True
, PDG assumes that the application be passed a list of file names and will open multiple files in the same application instance.
extToTag(extension)
→ str
Returns the file tag for the specified file extension.
filteredTags(prefix)
→ list
of str
Returns the list of tags with the specified prefix. For example, file/geo
or file/image
.
isMultiViewer(tag)
→ bool
Returns True
if the viewer application for the specified tag is capable of opening multiple files.
isViewable(tag)
→ bool
Returns True
if the specified file tag has a viewer associated with it.
For example, since by default the file/image
tag is viewable using the mplay
application that ships with Houdini, isViewable("file/image")
would return True
. On the other hand, isViewable("file/customfile")
would return False
unless a custom viewer is installed for that file tag.
nodeCallbackType(type_name)
→ pdg.NodeCallbackType
Returns a pdg.NodeCallbackType with the specified type_name
, or None
if one does not exist.
pathToTag(file_path)
→ str
Returns the file tag for specified file path.
pathToViewer(file_path)
→ str
Returns the viewer application name for the specified file path.
pathToExt(file_path)
→ str
Returns the full extension for the given path possibly including a known achive suffix, for example bgeo.sc.
pySerializationModule
: str
Property
The name of the module used to load and store PDG Python Object attributes during serialization. The default value is an empty string, which indicates that objects are stored using a simple repr
and eval
based serialization scheme.
tagToViewer(tag)
→ str
Returns the viewer application name for the specified file tag.
registerCacheHandler(tag, handler)
Registers a custom cache handler using the specified tag. When a work item checks if any of its expected output files exist on disk, this will call custom handlers before falling back to the built in cache file check. Handlers are called in order of most-specific to least-specific matching tag.
For example, a file with the output tag file/geo/collision
would first check against the file/geo/collision
handler, then the file/geo
handler, and so on. If any of the handlers returns pdg.cacheResult.Hit or pdg.cacheResult.Miss, then evaluation stops and that result is used. If no handlers return one of those results or no custom handlers are found, then PDG will determine if the file is cached by simply checking if it exists on disk.
See Custom File Tags and Handlers for more examples.
registerDirtyHandler(handler, handler_type=pdg.dirtyHandlerType.Any, scheduler_filter=[], node_filter=[], requires_outputs=False, is_global=False)
Registers a custom work item dirty handler
, which should be a function or callable object. The function is called any time a work item is dirtied or deleted, based on the specified handler_type
which should be a value from pdg.dirtyHandlerType
. The scheduler_filter
and node_filter
arguments can be used to restrict the handler to work items that are owned by nodes or schedulers of the specified types. If handler_type
is set to pdg.dirtyHandlerType.Files
and requires_outputs
is True
, the handler will only be called if the work item has one or more files that are being deleted. If the is_global
flag is True
the handler is invoked exactly once for each dirty operation, rather than per-work item, regardless of the number of work items involved.
For example, the following handler would be called each time a work item from the ropfetch
node is deleted:
def func(work_item, file_list): print(work_item) type_registry.registerDirtyHandler(func, handler_type=pdg.dirtyHandlerType.Delete, node_filter=['ropfetch'])
registerHashHandler(tag, handler)
#deprecated
This function is deprecated. Use pdg.TypeRegistry.registerStatHandler instead.
registerPreflightHandler(handler, generate_graph=False)
Registers a custom function that gets invoked each time the graph cooks. The function is called before any other operations in the graph cook are performed. if generate_graph
is True
, then static work items are generated before the handler function is called. If the function returns False
or throws an exception, the graph does not cotinue to cook.
For example, the following preflight handler prints basic information about the graph before it begins cooking:
import pdg def preflight(context, options): print("Preflight for context {}".format(context.name)) print(options) for node in context.graph.nodes(): print("Node: {} ".format(node.name)) print("Work Items: {}".format(node.workItems)) return True type_registry.registerPreflightHandler(preflight, True)
See Custom File Tags and Handlers for examples of how a custom handler can be installed when Houdini starts.
registerStatHandler(tag, handler)
Registers a custom file stat function using the specified tag. When a file without a hash or size is added to the work item, PDG will invoke custom stat functions that match the tag in order to determine a hash/file size value for that file. Handlers are called in order of most-specific to least-specific matching tag. If no stat functions are added, or none of the custom stat functions match the file tag, the built-in method of using the file’s mod time and file size on disk is used instead.
For example, a file with the output tag file/geo/collision
would first check against the file/geo/collision
handler, then the file/geo
handler, and so on. If a matching stat function returns a non-zero value for either the hash or size, that value is used and no other custom functions are called. If a custom stat function returns zero for both fields, PDG will continue down the list of matching functions until it finds one that returns a non-zero value, or ends up using the built-in mod time implementation.
If a stat function returns a value for one of the field, but not the other, PDG computes the missing field using its built-in logic.
See Custom File Tags and Handlers for more examples.
registerModuleTypes(module, quiet=False)
Registers custom types from the specified module.
registerDSOTypes(dso_path)
Loads C++ types from the specified shared library path.
registerNode(type_object, node_type, name=None, label=None, category=None, static_gen=True, sub_type=_pdg.nodeSubtype.Normal)
→ pdg.NodeCallbackType
Registers a custom node type. type_object
should be a Python class object
and node_type
should be a pdg.nodeType.
By default, the name and label will be set to the lower-cased Python class
name and the category will be left empty. The static_gen
flag indicates
whether or not the node should prefer to generate static work items when
it’s Generate When parameter is set to Automatic
.
registerPythonPath(path, update_tops)
Loads registered types from a Python module at the specified path.
registerScheduler(type_object, name=None, label=None, parm_category=None, node_category='Schedulers')
→ pdg.SchedulerType
Registers a custom scheduler type. type_object
should be a Python class object. By default, the name, label and parm_category are set to the lower-cased Python class name. The parm_category
is used to locate scheduler properties (Job Parms), and corresponds to their spare_category
. The node_category
is where the node will be found in the Houdini Tab-menu.
registerRegenerationHandler(handler)
Registers a custom handler that gets invoked when a node needs to regenerate work items. The handler can cause PDG to skip the regeneration process for the work item altogether, or enable regeneration but skip cache file invalidation due to attribute changes.
The handler should be a function that takes two arguments – a node and a list of work items. The function must return one of the enum entries defined in pdg.regenerateResult.
registerTransferHandler(tag, handler, use_mod_time=False)
Registers a custom handler that gets invoked when a work item or scheduler needs to copy files to the remote directory. The handler can choose to copy the file however it wants, or fall back to the default file copying logic. The handler is only called for files that begin with the specified tag.
If use_mod_time
is True
, the custom handler will still use the mod time caching logic that PDG uses internally. Otherwise the handler function will be expected to do its own caching logic to determine if the file needs to be re-copied.
registeredType(reg_type, name)
→ pdg.BaseType
Returns a PDG type object for the specified pdg.registeredType and type name.
registerWorkItem(type_object, name=None, label=None)
→ pdg.WorkItemDataType
Registers a custom work item type. type_object
should be a Python class object. By default, the name and label are set to the lower-cased Python class name.
registerService(type_name, type_label, command)
→ pdg.ServiceType
Registers a custom service type. type_name
is the identifier of the service type and should be unique. type_label
should be a human readable name for the service. command
should be a string that specifies the command line arguments that the PDG service manager will need to start client instances.
reloadCustomHandlers(existing=True)
Reloads all custom handlers, e.g. cache, file stat or preflight handlers, that were registered through Python. The module(s) that the handlers are defined in are also reloaed, so changes to the script files on disk will be picked up by PDG. If existing
is set to True
then PDG will only reload modules that were previously registered and contained at least one custom handler. Otherwise, if existing
is set to False
, PDG will reload all modules on the search path and re-register any handlers found in those modules.
schedulerType(type_name)
→ pdg.SchedulerType
Returns a pdg.SchedulerType with the specified type_name
, or None
if one does not exist.
serviceType(type_name)
→ pdg.ServiceType
Returns a pdg.ServiceType with the specified type_name
, or None
if one does not exist.
setDefaultWorkItem(item_type)
Sets the default work item type to the specified pdg.workItemType object.
setPySerializationModule(module_name)
Sets the name of the module used to serialize and deserialize Python object attributes. By default, the repr
of the object is used when saving work item data to send to the farm. If you specify a custom module name, the dumps
and loads
functions in that module are used instead to save and load the object respectively. For example, you can set the module to pickle
to make use of Python’s built-in serialization. Alternatively, you can also write your own serialization routines in a module and make it
accessible on Houdini’s Python path.
tags
: list
of str
Property
The global list of all file tags.
typeNames(reg_type, include_aliases=False)
→ list
of str
The list of type names for the specified pdg.registeredType. If include_aliases
is True
, then type names that are aliases to other concrete types are also included in the output list.
workItemDataType(type_name)
→ pdg.WorkItemDataType
Returns a pdg.WorkItemDataType with the specified type_name
, or None
if one does not exist.