Houdini 20.5 Nodes TOP nodes

Attribute from String TOP node

Parses attribute values from a string, such as a file name.

On this page
Since 17.5

The node lets you choose between 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, alternating named “capture” groups and literal characters. The strings captured by the groups are assigned to attributes. This can be useful for parsing information out of file names, if the name has a regular structure with separator characters.

For example, given “source” file names in the form:

shot_a.simcache.1.005.bgeo.sc

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

{shot}.{}.{wedgenum}.{frame}.bgeo.sc

(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 {shot} 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}.

  • 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.

Source String

The string containing data you want to parse. Usually this is an expression to get the string from an attribute. Since this is a string parameter, you need to enclose the expression in back-ticks. For example: `@name`

Operation

Determines which operation to perform on the source string. Match by String will extract components from the Source String using a pattern and store them as attributes. Split by Delimiter will split the source string based on a secondary string and store the resulting substrings as attributes.

Match by Pattern

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 the Source string. 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 incoming items where the pattern matched. When this is on, work items are passed through even if they didn’t match.

Split by Delimiter

Delimiter Type

Specified what type of delimiter to use for splitting the Source String. Using String will split the source string based on the exact contents of the Delimiter field. Character Set attempts to split based on each of the delimiter characters individually. Regular Expression will interpret the Delimiter as a custom regex.

Delimiter

The delimiter to use when splitting the source string.

Store Result As

How the split string is stored. The components can either be stored as a string array attribute on a single work item, or split into one work item per component.

Split Attribute

The name of the attribute created on each work item that contains the split compenents from the Source String. If this parameter is disabled then no attribute is created.

Count Attribute

The name of the attribute created on each work item that contains the total number of delimiter-separated components in the Source String. If this parameter is disabled then no attribute is created.

Index Attribute

When Store Result As is set to Separate Work Items, this parameter determines the name of the attribute created on the work items to identify their position in the split component list. If this parameter is disabled the no attribute is created.

Trim Whitespace

When this toggle is enabled, leading and trailing whitespace is removed from the components after splitting the string.

Examples

RegexPattern Example for Attribute from String TOP node

This example demonstrates how to create work item attributes using a regex pattern or delimiter.

SimplePattern Example for Attribute from String TOP node

This example demonstrates how to create work item attributes from string data using a simple pattern matching syntax.

See also

TOP nodes