[Smtk-developers] Help
Shukla, Indu ERDC-RDE-ITL-MS
Indu.Shukla at erdc.dren.mil
Fri Jun 26 14:21:27 EDT 2015
Thank you so much David.
-----Original Message-----
From: David Thompson [mailto:david.thompson at kitware.com]
Sent: Thursday, June 25, 2015 5:31 PM
To: Shukla, Indu ERDC-RDE-ITL-MS
Cc: Yumin Yuan; smtk-developers at smtk.org; Hines, Amanda M ERDC-RDE-ITL-MS
Subject: Re: [Smtk-developers] Help
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