Creating waypoints while the code is running

In my UR10 script I want to be able to us until contact to make it so that my tool keeps going until it makes contact with my item and from there it creates a waypoint at the spot where it made contact. Then I will move my arm certain distance until it makes contact with another point of the item and it will create another waypoint. From there I want it to go back to the first waypoint and move in the distance between the 1st and 2nd.

you can get the contact points using get_actual_tcp_pose() and save it in a variable.
then use that variable as the parameter for your movej or movel.

Thankyou it worked fine