Jump to content

I have a date range filter and I am trying to cast its max value to a document property however i keep getting an error that says max_value is undefined.


Matt McDowell

Recommended Posts

from Spotfire.Dxp.Data import DataProperty 

from Spotfire.Dxp.Data import DataType 

from Spotfire.Dxp.Data import DataPropertyClass 

from Spotfire.Dxp.Application.Filters import RangeFilter 

from Spotfire.Dxp.Application.Visuals import VisualContent 

from System import Guid

# Get the active page

page = Application.Document.ActivePageReference

# Find the Filter named "FlowDay" on the page 

for visual in page.Visuals:

  if visual.Title == "FlowDay":

    # Check if the visual content is a RangeFilter

    if isinstance(visual, VisualContent):

      # Cast the visual content to a RangeFilter

      flow_day_filter = visual.As[RangeFilter]

      if flow_day_filter:

        # Retrieve the ValueDataRange property

        value_data_range = flow_day_filter.ValueDataRange

        # Get the minimum and maximum values

        min_value = value_data_range.MinValue

        max_value = value_data_range.MaxValue

myPropertyName = "myNewDocumentProperty" 

myAttributes  = DataProperty.DefaultAttributes 

myProperty  = DataProperty.CreateCustomPrototype(myPropertyName, DataType.Date, myAttributes) 

#Create the Property, catch if it fails/exists.

try:

 Document.Data.Properties.AddProperty(DataPropertyClass.Document, myProperty) 

except:

 print("Property creation failed. Does it already exists?")

#Set the Property

#Document.Properties[myPropertyName] = max_value

Link to comment
Share on other sites

I am guessing it never finds the visual element, so max_value is unset. A RangeFilter is not a visual element.

This code worked for me: you need to specify the name of the filtering scheme you are using (it will be the default "Filtering scheme" if you did not create more than one), the name of the data table and of the date column (here I used the Movies dataset as an example).

from Spotfire.Dxp.Application.Filters import *from Spotfire.Dxp.Data import * # Specify data table and columndata_table = Document.Data.Tables["Movies"]column= data_table.Columns["ReleaseDate"] # Find the specified filtering scheme on the data tablefilter_selection = Document.Data.Filterings["Filtering scheme"]  # Get rows and find max value (extract date time value from it)rows = filter_selection.GetSelection(data_table).AsIndexSet()max_value = column.RowValues.GetMaxValue(rows)max_value=max_value.ValidValue  ### Create and set property - as beforemyPropertyName = "myNewDocumentProperty" myAttributes = DataProperty.DefaultAttributes myProperty = DataProperty.CreateCustomPrototype(myPropertyName, DataType.DateTime, myAttributes)  #Create the Property, catch if it fails/exists.try: Document.Data.Properties.AddProperty(DataPropertyClass.Document, myProperty) except: print("Property creation failed. Does it already exists?") #Set the PropertyDocument.Properties[myPropertyName] = max_value
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...