[Smtk-developers] Help

David Thompson david.thompson at kitware.com
Fri Jun 26 15:19:16 EDT 2015


Hi Indu,

I'm a little unclear on exactly what information you want to get from the "Tide-0" attribute.

	David

> On Jun 26, 2015, at 3:16 PM, Shukla, Indu ERDC-RDE-ITL-MS <Indu.Shukla at erdc.dren.mil> wrote:
> 
> David, Yumin,
> 
> This code 
> 
> att = asys.findAttribute('Globals')
> gr = att.findGroup('ProjectInformation')
> nm = smtk.attribute.to_concrete(gr.find('ProjectName'))
> #print nm.value(0) 
> 
> Works great to access the InstanceView items. How to I access items and its values in attribute view? Here's my example.
> 
>    <Att Name="Tide-0" Type="Tide" ID="6">
>      <Items>
>        <Group Name="Gage Station">
>          <String Name="Station">station</String>
>          <String Name="Agency" Discrete="true">0</String>
>          <String Name="Station ID">1234</String>
>        </Group>
>        <Group Name="Latitude">
>          <String Name="Degree">0</String>
>          <String Name="Minutes">0</String>
>          <String Name="Seconds">0</String>
>          <String Name="Directions" Discrete="true">0</String>
>        </Group>
>        <Group Name="Longitude">
>          <String Name="Degree">0</String>
>          <String Name="Minutes">0</String>
>          <String Name="Seconds">0</String>
>          <String Name="Directions" Discrete="true">0</String>
>        </Group>
>        <String Name="Description">
>          <UnsetVal />
>        </String>
>      </Items>
>    </Att>
> 
>    <Att Name="Wind-0" Type="Wind" ID="7">
>      <Items>
>        <Group Name="Gage Station">
>          <String Name="Station">wind station</String>
>          <String Name="Agency" Discrete="true">0</String>
>          <String Name="Station ID">1234</String>
>        </Group>
>        <Group Name="Latitude">
>          <String Name="Degree">0</String>
>          <String Name="Minutes">0</String>
>          <String Name="Seconds">0</String>
>          <String Name="Directions" Discrete="true">0</String>
>        </Group>
>        <Group Name="Longitude">
>          <String Name="Degree">0</String>
>          <String Name="Minutes">0</String>
>          <String Name="Seconds">0</String>
>          <String Name="Directions" Discrete="true">0</String>
>        </Group>
>        <String Name="Description">
>          <UnsetVal />
>        </String>
>      </Items>
>    </Att>
> 
> 
> Thank you!
> 
> Indu
> 
> -----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