How to create a thread with scripts

Hi,
how can i write a thread with arguments using scripts?

Elottrotec_AC14,
Can you explain a little bit more on what your trying to do?

You cant write a Thread in a script file.
however you can call a def routine in a script file from a Thread
or write single script commands in Polyscope within a Thread.

You also can’t pass arguments through a thread. You will have to have the thread utilize global variables instead if you want to “pass” information into it. And you CAN write threads into a script file:

image

You can read more in the script manual here: https://s3-eu-west-1.amazonaws.com/ur-support-site/115824/scriptManual_SW5.11.pdf

Just ctrl+F for “thread”

Thanks eric.feldmann,
This why I love the forum there’s so much knowledge from everyday users with different experiences.

Every days a school day!

No, but you can wrap a thread in a function and get around it:

You can create a function that takes arguments and inside that function, you can take those args, redeclare them with different names as global, and now your thread can use them inside that function.

If you want to see an example, try using an IF with the continuous box checked and see how UR implements this in their .script file generated when you run the URP.

Literally just did this for something 5 mins ago (Not super experienced with the whole join, kill stuff in urscript so test this)


def threaded_function(a, b):
    global c = a
    global d = b

    thread my_thread():
        textmsg("value of a", a)
        textmsg("value of b", b)
    end

    my_handler = run my_thread()
    join my_handler
end

Hello terryc,
I’m new in writing threads, my question is, if you would have an digital input which goes on false, because the spindle is crashed… I’ll interrupt the movement of the program, with “halt”.
Can you help with a sample or an idea how to combine both events.
Thanks Birgit