Matt McDowell Posted October 24, 2023 Share Posted October 24, 2023 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 pagepage = 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.MaxValuemyPropertyName = "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 More sharing options...
Gaia Paolini Posted October 26, 2023 Share Posted October 26, 2023 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now