Reset some attributes quickly, script make clarisse crash

hello,
I wrote a script through piecing and copying. This script can reset some attributes of autodesk material quickly.
I'm not very good at scripting.
When I run this script, sometimes it works fine and sometimes it make clairsse crashes.
I don't understand why.
Here's how I ran it:
Select aa ->Run script -> fine
Select bb ->Run script -> fine
Select cc ->Run script -> fine
Select aa again ->Run script -> clarisse crash
Select aa ->Run script -> fine
Select bb ->Run script -> fine
Select cc ->Run script -> fine
Modify some attributes of bb ->Select bb ->Run script -> clarisse crash
I want to know which make it crashed, a bad script or clarisse's bug?
I would appreciate it if anyone could help me improve this script.
Script is in kk.ple and kk.ple is in attachment.
I wrote a script through piecing and copying. This script can reset some attributes of autodesk material quickly.
I'm not very good at scripting.
When I run this script, sometimes it works fine and sometimes it make clairsse crashes.
I don't understand why.
Here's how I ran it:
Select aa ->Run script -> fine
Select bb ->Run script -> fine
Select cc ->Run script -> fine
Select aa again ->Run script -> clarisse crash
Select aa ->Run script -> fine
Select bb ->Run script -> fine
Select cc ->Run script -> fine
Modify some attributes of bb ->Select bb ->Run script -> clarisse crash
I want to know which make it crashed, a bad script or clarisse's bug?
I would appreciate it if anyone could help me improve this script.
Script is in kk.ple and kk.ple is in attachment.