Dropdown in perspective

Hello,
In Perspective, I would like to trigger a script when a value is deleted from a dropdown.

I don't know the name of the event.

Thank you

Do you mean when an item is no longer available in the options property, or when someone hits a clear button to set the selected value to None?

Hi,

The event when someone press the cross in the value of the dropdown

Capture d’écran 2025-11-11 153731

Since those are stored in props.value parameter and you want to trigger only when something is deleted, I would use a change script on props.value. Then compare the length of previousValue.value and currentValue.value to see if something was removed from it

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	# grab the previous and current array length, default to 0 if null
	previousLen = len(previousValue.value) if previousValue.value else 0
	currentLen = len(currentValue.value) if currentValue.value else 0
	
	# if array length reduces
	if previousLen > currentLen:
		# default current array to [] in case of null
		currentValueArray = currentValue.value or []
		# find the difference aka whatever was removed if needed
		difference = [value for value in previousValue.value if value not in currentValueArray]

		system.perspective.print('Array length reduces from %s to %s' % (previousLen, currentLen))
		system.perspective.print(difference)
2 Likes

Thank you for your reply, sorry but where must I write the script ?

Right click on the value prop in the property editor, then you’ll see the option to add a change script.

1 Like

Thanks for your help

Regards

Hello,

If the dropdown is empty, the previousValue has no value.How to fix it?

Thanks

What is the error message?

'NoneType' object has no attribute 'value'

Just test for it. Something like,

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if not previousValue:
		return
	# grab the previous and current array length, default to 0 if null
	previousLen = len(previousValue.value) if previousValue.value else 0
	currentLen = len(currentValue.value) if currentValue.value else 0
	etc.
2 Likes