Jump to content

Use IronPython to get checked items in a CheckboxHierarchyFilter


Matthew Henrich

Recommended Posts

I am attempting to write an IronPython script that will look at all nodes of a CheckboxHierarchyFilter and return only the values that are currently checked.

This question was similarly asked here:https://community.spotfire.com/questions/iterate-through-items-checkboxhierarchy-filterand that is how I got the base level (*.Heirarchy.Level[0]), but I cannot get the 2nd - 4th levels to be read correctly. When I try to follow the instructions on that page/question, I keep getting a "Looking for Array(DistinctDataValue), but got bool." error.

Can someone enlighten me on how to do thisIsChecked(List) doesn't seem to be the right answer.

Link to comment
Share on other sites

  • 6 months later...

Hi Matthew -

I did write and post an article on this topic at the time, but it looks like my comment pointing you to that script was missed somehow. Let me share the link to the script with you:

https://community.spotfire.com/s/article/Hierarchical-Checkbox-filters-which-values-are-checked

Do let us know if it solves your issue!

We appreciate your feedback,

Andrew

Link to comment
Share on other sites

Hi Matthew,

OK - here is how you can tell if an item is checked:

import Systemfrom System import Arrayfrom Spotfire.Dxp.Data import DistinctDataValueimport Spotfire.Dxp.Application.Filters as filtersfrom System.Collections.Generic import List myPanel = Document.ActivePageReference.FilterPanelmyFilter = myPanel.TableGroups[0].GetFilter("New hierarchy")chFilter = myFilter.FilterReference.As[filters.CheckBoxHierarchyFilter]() l = List[DistinctDataValue]() l.Add(DistinctDataValue("California"))l.Add(DistinctDataValue("conventional"))print(chFilter.IsChecked(l))

The values "California" and "conventional" are the values in levels 1 and 2 in the hierarchy I'm using.

The original example I posted is more generic - in that it recursively navigates the entire hierarchy.

Hopefully you can translate that to your needs. Let us know how you get on!

Andrew

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...