简体   繁体   中英

iron python script for List box filter in spotfire

I have a script like below -

from Spotfire.Dxp.Application import Filters as filters
import Spotfire.Dxp.Application.Filters.ListBoxFilter
from Spotfire.Dxp.Application.Filters import FilterTypeIdentifiers
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Filters import *

CurPanel = Document.ActivePageReference.FilterPanel
FilterA = CurPanel.TableGroups[1].GetFilter("column_name1")
CheckBoxesA = FilterA.FilterReference.As[filters.ListBoxFilter]()
FilterB = CurPanel.TableGroups[0].GetFilter("column_name2")
CheckBoxesB = FilterB.FilterReference.As[filters.CheckBoxFilter]()
print "success1"
for CheckBoxVal in CheckBoxesB.Values: CheckBoxesB.Uncheck(CheckBoxVal)
   print "success2"
str = CheckBoxesA.ToString()
found, nodes = myTable.Columns ["column_name2"].Hierarchy.Levels.LeafLevel.TryGetNodes(int.MaxValue)
for node in nodes:
   if str.Contains("All"): CheckBoxesB.check(node.Value.ValidValue)
   if str.Contains(node.Value.ValidValue): CheckBoxesB.check(node.Value.ValidValue)

This works completely fine when I use CheckBoxFilter in line 10. But for the values more than 100, as spotfire automatically considers list box filter, I should modify the line 10 as below -

CheckBoxesB = FilterB.FilterReference.As[filters.ListBoxFilter]()

Then I get the following error message -

success1 Traceback (most recent call last): File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging File "", line 16, in AttributeError: 'ListBoxFilter' object has no attribute 'Values'

System.MissingMemberException: 'ListBoxFilter' object has no attribute 'Values' at stub $619##619(Closure , CallSite , Object , CodeContext ) at Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func4 target, CallSite site, Object[] args) at Microsoft.Scripting.Actions.CallSite1.UpdateAndExecute(Object[] args) at Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at $606##606(Closure , Scope , LanguageContext ) at Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary2 scope, Stream outputStream)

I understand issue with uncheck and check functions used in lines 12 and last two lines. Is there any equivalent function to be used for list box filter ?

It doesn't look like there's an exact equivalent, but there are a couple ways you could do this.

First, there is a method IsSelected, where you could determine if All is selected or not, and reset the filter accordingly.

if CheckBoxesB.IsSelected('All') ==  True:
  CheckBoxesA.Reset()

You can set the values if needed using a string list, as shown here: http://spotfired.blogspot.com/2014/03/change-filters-programatically-from.html

If for whatever reason you actually need to get the specific values that have been selected from the filter, you can see them with this addition of this code:

CurPanel.InteractiveSearchPattern = "status:m"
for filters in CurPanel.FiltersMatchingSearchPattern:
    ##Optional Table name to find column in specific table
    #if str(filters.ParentGroup) == "Table_Name":
    print filters.FilterReference.ToString()

Which displays the Filter Column name first, and then the selected values in a string list. You can adjust this accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM