Place fiducial every n seconds

Hi, I am new to programming in 3D slicer. I am trying to place a fiducial at the tip of the pointer tool every five seconds. I have tried using the timer function but it doesn’t seem to work. This is the code I am using:

from threading import Timer

def test():
fidMatrix = vtk.vtkMatrix4x4()
Transform.GetMatrixTransformToWorld(fidMatrix)

slicer.modules.markups.logic().AddFiducial(fidMatrix.GetElement(0,3),fidMatrix.GetElement(1,3),fidMatrix.GetElement(2,3))
Timer(5,test).start()

test

QTimer works well, see for example Endoscopy module.

However, before implementing anything, consider these existing point recording options:

You can use “Collect Points” module in SlicerIGT extension. It supports sampling based on minimum distance, can record points in arbitrary coordinate system, control labeling (base name and counter), etc. It does not sample by elapsed time, but if you are sure you want to sample by time then we might consider adding it.

You can also record points into sequence nodes by going to Sequences module, click the green ‘+’ button to create a new sequence, choose the transform node as “Proxy node” in the table, then hit the red “Record” button. After recording, you can also replay, and access recorded point positions as a sequence node. By default maximum recording rate is limited to the current playback rate, so to achieve sampling at every 5s, set playback rate to 0.2fps.

Thanks thats great!
I used the Qtimer and it is working perfectly.