This is probably very simple thing but i 'm not very familiar with script yet
I want to make a program that loops specific lines according to operator input.
I didn’t find the script for that from the manual.
There is the “Loop when expression is true” but how i can make it read the operator input.
In Polyscope try adding an assignment but change it from “Expression” to “Operator” then add some text instruction for operator input before the loop. Also add a count variable
OperatorInput:=‘Number of times to loop’
Count:=0
Then you can add the loop
Loop Count < OperatorInput:
// Do some stuff
// OperatorInput:=‘Change number of times to loop // added inside in case this changes and operator needs to adjust number of times within the loop
Count:=Count+1 // if Count is made an installation variable you can use the “SET” node to increment this value, just remember to add Count:=0 at the start of your program
// sync() // use up remaining physical time
Sorry might have been a lot but urcommunity might have other better options. Hope that helps and best of luck!
I like to mention this whenever possible, because it is so handy. If you ever say “I can do this in Polyscope, how can I do it in script?” then this is the answer, every time!
First, just make the program in Polyscope. As @MikeM points out, you can use the Assignment node and switch it to Operator as the source
Now, for the magic. Save this program as anything you’d like. Now add a “Script” node to Polyscope, and switch it from “Line” to “File” in the top right. Then click the Edit button
Click the Open button in the top left, and Open the file you just saved. What you’ll see is the exact URScript that Polyscope built behind the scenes. This means you could instead write exactly what’s here, delete your entire Polyscope program, and it will do the same thing.
(The lines starting with a dollar sign $ are just labels that correspond to the line number. The actual lines of code being executed are the lines without those $)
So As you can see, in order to assign the variable “input” through the operator, it looks like Polyscope wrote global input=request_integer_from_primary_client("")
Therefore that’s the line of script you’re probably looking for as well! Hope this helps.
Ok, so I was on the right track actually, i just missed couple small details.
And i thought there is some more simple ways to read the operator input than use counter variables etc. like just one script line in the loop node but this seems to work well too
Thanks guys, this was helpful for the future as well!
I found this topic about using a loop according a variable entered by an operator.
I use the polyscope code in my program, but unfortunately it doesn’t seem to work.
When I start the program, the screen appears to fill in the numbers, after that the pop-up appears
with the message to stop the program or to continue, but I have to push the continue button until
the entered numbers are correct and then it starts all over again.
It is propably very simple, but I could not find the clue yet.
I hope that this would help! The program is mainly in Dutch, because that is the default setting of our UR3.
If it is a problem I could translate the words.
That almost looks more like some code for debugging. Can you just suppress (or delete) the loop there? I don’t know any benefit of just displaying on the screen the robot counting from 0 to whatever you typed in…
Sorry, so are you good now? Or are you asking how to ask the operator to re-enter a value? Because all you have to do for that is copy the line in the before start, the “OperatorInput = ‘enter quantity’” line and then reassign count to 0 and you’re done.