How can I get camera position information?

Operating system: window 11
Slicer version: 4.13.0

Hi , everyone

I would like to know about camera coordinates, viewup vector, and focal point information based on the first time I ran 3d slicer.

so, I used follow code

viewNode = slicer.mrmlScene.GetSingletonNode(“1”, “vtkMRMLViewNode”)
cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(viewNode)
print(cameraNode.GetPosition())

but result : 000001dd…_p_void

How can I get camera coordinates like [x,y,z] based on ras coordinates or view coordinates?

It seems that a vector length hint was missing in the GetPosition call, therefore a raw pointer is returned. We’ll fix this. Until then you can use this syntax:

p=[0,0,0]
cameraNode.GetPosition(p)
print(p)

Please use the current version of Slicer, especially for development.

1 Like

I’ve submitted a pull request to add the missing size hints, which will make GetPosition() syntax work as expected. The fix will be available in the Slicer Preview Release within a few days.