Houdini 20.5 Nodes TOP nodes

Attribute from File TOP node

Parses attribute values from a file into work items.

On this page
Since 20.0

The node lets you choose a (regex) delimiter between sets of attributes listed in a file; for files with work item data separated line-by-line, this delimiter would be \n. The text for each attribute set is futher parsed into a new work item by using a simple pattern replacement language, or full-on regular expressions. The simple patterns are easier to write and make sense to use for structured strings with separators.

Simple pattern language

This node supports a fairly simple pattern language (similar to the Attribute from String node), alternating named “capture” groups and literal characters. The strings captured by the groups are assigned to attributes. This can be useful for parsing information formatted in a regular structure with separator characters.

For example, given a line in a file describing a set of attributes in the form:

"cat","cat0.png",1

You can parse the different parts into attributes using a pattern such as:

"{name}","{filename}.{}",{size:int}

(Empty braces capture a string but aren’t assigned to an attribute.)

  • In the pattern, curly braces ({‹name›}) match up to the next literal character in the pattern.

    • If the braces are empty, the matching string is thrown away.

    • The braces contain a name, the matching string is assigned to an attribute with that name. For exmaple, the part of the source string “captured” by {name} is assigned to the shot attribute.

    • If Infer attribute type is on, the node guesses the attribute type based on the matched string (if it looks like a whole number, it’s an integer; if it looks like a number with a decimal point, it’s a float; otherwise it’s a string). You can explicitly specify the type using {‹name›:‹type›}. For example, {shot:string}, {frame:int}, {time:float}.

    • Braces with no type or a string type only match text containing alphanumeric characters and underscores. Formally, they match text using the regex \w+.

  • If you have capture braces at the end of the pattern, they match to the end of the source string.

  • Outside braces, characters in the pattern must match characters in the source string exactly.

  • Braces are not “greedy”… they only match up to the next literal character, even if going further would give a better match.

    For example, in day.01.csv, with the pattern {name}.csv you might expect {name} to capture day.01, but in fact it will only capture day (since it captures up to the next literal character, a period). The pattern will then fail because it expects the characters after the period to be csv, not 01.

  • The whole pattern must match the source string (not just a prefix).

  • If the whole pattern doesn’t match, none of the attributes in the pattern will be set.

Regular expression

For maximum power/flexibility, you can use a regular expression instead. This node uses Python’s regular expression syntax.

  • Using a regular expression implies Infer attribute type.

Parameters

Generate When

Determines when this node will generate work items. You should generally leave this set to “Automatic” unless you know the node requires a specific generation mode, or that the work items need to be generated dynamically.

All Upstream Items are Generated

This node will generate work items once all of the input nodes have generated their work items.

All Upstream Items are Cooked

This node will generate work items once all of the input nodes have cooked their work items.

Each Upstream Item is Cooked

This node will generate work items each time a work item in an input node is cooked.

Automatic

The generation mode is selected based on the generation mode of the input nodes. If any of the input nodes are generating work items when their inputs cook, this node will be set to Each Upstream Item is Cooked. Otherwise, it will be set to All Upstream Items are Generated.

File Path

Path of the file to parse.

Work Item Delimiter (regex)

Separator regular expression between text containing attribute values for a work item.

Pattern Type

Determines if the Pattern field is using the simple brace syntax or a regular expression. When using a regular expression, captured groups are assigned to attributes by number, for example, group0, group1, and so on. If the capture groups are named, e.g. using the syntax (?P<name>), then the attribute name is set to the capture group name.

Pattern

The pattern to use to extract attributes from each string in a delimiter-separated file. The language is controlled by the Use custom regex checkbox. When the checkbox is off, this parameter uses a simple pattern substitution language (see above). When the checkbox is on, this parameter is a regular expression.

Infer Attribute Type

When this is on, if you don’t explicitly state the type of a capture pattern (for example, {shotnum:int}), the node will try to guess the type based on the matched string content (if it looks like a whole number, it’s an integer; if it looks like a number with a decimal point, it’s a float; otherwise it’s a string).

Create Items With No Matches

By default, the node only creates new work items from a string where the pattern matched. When this is on, work items are created even if they didn’t match.

Parsing Issues

How to report parsing issues such as a failed match.

See also

TOP nodes