Need to touch up motion statements created using python

Hi. I created a PTP motion for a UR3 robot using this Python script

from vcScript import *

app=getApplication()
comp=getComponent() 
robot=comp.findBehaviour("Executor")
prog=robot.Program
main=prog.MainRoutine
main.clear()

s=main.addStatement(VC_STATEMENT_PTPMOTION)
matrix=s.Positions[0].PositionInWorld
vec=matrix.P
vec.X=230
vec.Y=431
vec.Z=1215
matrix.P=vec
s.Positions[0].PositionInWorld=matrix

It works fine in Visual Components when I click the play button. But when I click Export → Post Process to export as a script, I get all zeroes in the movej

def script():
  set_tcp(p[0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000])
  movej([0.000000,0.000000,0.000000,0.000000,0.000000,0.000000],v=3.142)
end #script
script()

Then if I go back to Visual Components and click “Touch up” on the motion statement, the export works fine and I get

def script():
  set_tcp(p[0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000])
  movej([3.069233,-2.115247,1.896788,1.789200,-1.570741,1.643185],v=3.142)
end #script
script()

So how can I modify my Python script so I don’t need to click touch-up ? And what does touch-up do?

Touch-up updates the joint values and other properties of the motion statement. There are readIn and writeTo methods in the API for motion statements. The simplest way in your code would probably be to just get handle for the Robot Controller, create a motion target using the matrix, move the robot to target, and then either create motion statement or update it using readIn.

I don’t remember, but you can also try to make variable to reference position of statement, set its matrix, and then assign position back to the statement. However, I don’t remember if that will work with “default” statements like LIN and PTP.