I am working on a script where I am problematically controlling Check Box filters.
#CheckBoxFilter #PythonScript #check&UnCheck
Hi All,
I am working on a script where I am problematically controlling Check Box filters.
Step 1: Run script to perform 'Uncheck all' on a particular filter (Done - can share code if you want)
Now all values are unchecked.
Step 2: A button click should check first unchecked value. Second click should check the second value (Now total two values are checked) and it goes on like this.
Example: Filter Name: country || Values: US, UK, Canada, Australia, China
First click will show data of US, second click will show data of US & UK, 3rd (US+UK+ Canada) and when all are checked it will give a message all values checked.
Can somebody please help me on this.
(7) Answers
This is a sample of what I use. This sets 4 different check box filters to the defaults I want.
from Spotfire.Dxp.Application.Filters import CheckBoxFilter
#set reference to checkbox filter
filter1=Document.FilteringSchemes[0].Item[LeaseOperatingExpensesReport].Item[LeaseOperatingExpensesReport.Columns.Item["OP/NON-OP"]].As[CheckBoxFilter]()
#uncheck all then set defaults
filter1.IncludeEmpty = False
for value in filter1.Values:
filter1.Uncheck(value)
#set defaults
filter1.Check("Y")
#set reference to checkbox filter
filter2=Document.FilteringSchemes[0].Item[LeaseOperatingExpensesReport].Item[LeaseOperatingExpensesReport.Columns.Item["Current_Primary_Status_Description"]].As[CheckBoxFilter]()
#uncheck all then set defaults
filter2.IncludeEmpty = False
for value in filter2.Values:
filter2.Uncheck(value)
#set defaults
filter2.Check("Producing")
#set reference to checkbox filter
filter3=Document.FilteringSchemes[0].Item[LeaseOperatingExpensesReport].Item[LeaseOperatingExpensesReport.Columns.Item["Cost_Center_Business_Unit_Description"]].As[CheckBoxFilter]()
#uncheck all then set defaults
filter3.IncludeEmpty = False
for value in filter3.Values:
filter3.Uncheck(value)
#set defaults
filter3.Check("EAST TEXAS")
filter3.Check("MID-CON EAST")
filter3.Check("MID-CON WEST")
#set reference to checkbox filter
filter4=Document.FilteringSchemes[0].Item[LeaseOperatingExpensesReport].Item[LeaseOperatingExpensesReport.Columns.Item["Include-Exclude"]].As[CheckBoxFilter]()
#uncheck all then set defaults
filter4.IncludeEmpty = False
for value in filter4.Values:
filter4.Uncheck(value)
#set defaults
filter4.Check(">=12 Months Prod")
filter4.IncludeEmpty = True

Thanks Chris but I am looking for more dynamic solution. Filter where I want to use this script has >100 unique values. So it wouldn't be possible to name all of them in script. Plus data is dynamic.
What I want is after all values are unchecked.. a button click should check the very fiirst value.. next click next value and so on.
Do you have any script/suggestion for this?

Here's a quick solution I put together. I've got two buttons, one that will uncheck all values and one that will check the next value after each click. Both buttons are tied to the same script, but the buttons are parametrized with a methodID that calls either the uncheck (methodID=1) or check next method (methodID=2). Here's the code and a screenshot. Let me know if you have any questions.
from Spotfire.Dxp.Application.Filters import CheckBoxFilter
import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import MessageBox
def Method1(myFilter):--#uncheck all--myFilter.IncludeEmpty = False--for value in myFilter.Values:--myFilter.Uncheck(value)
def Method2(myFilter):--#check next filter--checkCounter = 0--for value in myFilter.Values:--if myFilter.IsChecked(value) == False:--myFilter.Check(value)--checkCounter = checkCounter + 1--break--if checkCounter ==0:--MessageBox.Show("All values checked")
#set reference to checkbox filter
myFilter=Document.FilteringSchemes[0].Item[myDataTable].Item[myDataTable.Columns.Item["country"]].As[CheckBoxFilter]()
#call method based on ID
callMethod={1:Method1, 2:Method2}
callMethod[methodID](myFilter)
1 Comment
Hi Chris,
Kindly help on below spotfire query.
https://community.tibco.com/questions/how-create-dynamic-check-and-unche...

1 Comment
Hi Chris,
Kindly help on below spotfire query.
https://community.tibco.com/questions/how-create-dynamic-check-and-unche...
Here's the screenshot (methodID is 2 because this is the code behind the check next button). The uncheck all button has the same script reference, but methodID is 1 instead.
Attachment | Size |
---|---|
![]() | 282.86 KB |

Similar Questions
Haven't found what you are looking for?
Existing Best Answer
This Question already has a 'Best Answer'. If you believe this answer is better, you must first uncheck the current Best Answer