The best place to discuss generic scripting questions is the Scripting forum, not the 2D forum so I’ll move your post for you.
FYI: Here’s how to post code using code-tags .