[Smtk-developers] Help
David Thompson
david.thompson at kitware.com
Thu Jun 25 18:30:46 EDT 2015
Hi Indu,
> ...
> att = asys.findAttribute('Globals’)
> gr = att.findString('ProjectName')
> gr = att.findGroup('ProjectInformation')
> gr.find('ProjectName')
>
> Please let me know how can I access the value of my ProjectName.
The issue is that the "find" methods return a Python object that corresponds to the base "Item" type (which does not have methods to fetch data since no data format is specified in base class). The base Item must be converted to one of the proper type (StringItem in this case), which is done with smtk.attribute.to_concrete(). Either of these should work:
1. Fetch each item in the hierarchy
att = asys.findAttribute('Globals')
gr = att.findGroup('ProjectInformation')
nm = smtk.attribute.to_concrete(gr.find('ProjectName'))
print nm.value(0)
2. If you have a *really* recent SMTK (fetched within the last few days), you can do this:
att = asys.findAttribute('Globals')
nm = smtk.attribute.to_concrete(
att.itemAtPath('ProjectInformation/ProjectName', '/'))
print nm.value(0)
where the '/' argument to "itemAtPath" is a separator character that divides the first argument into the list of items to descend.
There appears to be a bug in the variant of att.find() that takes a smtk.attribute.SearchStyle as its second argument or there would be a third way. Hopefully one of the above will work for you until it is fixed.
David
More information about the Smtk-developers
mailing list