ScriptSpot

Forum topic · General Scripting

Prevent Runtime error: No such modifier in node 1

By timbo2000 · 2015-04-28

Description

I've created a dialog box script which can create an object and then add and remove modifiers. To remove modifiers one-by-one from the stack (like an undo command), I have added a button:

on but_undo pressed do
(
deletemodifier obj 1
)

Only problem is that it's still possible to try and remove a modifier even when the stack is empty, which results in a runtime error: No such modifier in node 1

Is there a way that I can disable the button if the modifier stack is empty? Failing that, is there a way to prevent it from attempting to delete a modifier if there isn't one there to delete? Or am I just going about this the wrong way to start with?

Comments (2)

.

miauu · 2015-04-29

Or count the mdifiers:


on but_undo pressed do
(
	if obj.modifiers.count != 0 do
		deletemodifier obj 1
)

`

pixamoon · 2015-04-28

the simplest way is to just add

try(  )catch()

:


on but_undo pressed do
(
try(deletemodifier obj 1)catch()
)

you can also use callbacks to turn off button, but its bit more complicated