Search - User list
Full Version: Attribute shorthand in Python expressions
Root » PDG/TOPs » Attribute shorthand in Python expressions
jamesr
Hey guys, quick question:

Is there anything similar to the
`@attribname`
shorthand when writing python expressions on parameters in TOPs? Currently I've been using
pdg.workItem().stringAttribValue()
etc.


Oh and aside question - when using the shorthand syntax in a python script TOP, sometimes it finds the attributes just fine, others it only works with
work_item.attribValue("someattributename")
. Are there any rules to follow when using
"`@attrib`"
syntax in a python script TOP? So far I just do trial and error, and if it doesn't cook I switch to the long way.

Thanks!
tpetrick
Backtick expansion, e.g. expression like `@attrib`, are not part of the Python script. They're part of Houdini's string parameter evaluation, and get filled in when PDG evaluates the script parm on the node and stores the script contents on the work item. That occurs when the work items are being generated. If the attribute doesn't exist when the item is being generated, then the @attrib access will evaluate to nothing.

You can also use pdg.workItem() to access attributes. That returns back an attribute object, such as a pdg.AttributeFloat [www.sidefx.com] – the type of the object it returns depends on the type of the attribute. You can then use the array bracket operator to access values, for example:

pdg.workItem()['position'][1]
jamesr
Great, thank you for the explanation!

I will give the example snippet a try.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB