# Camera Observer Arguments

**URL:** <https://discourse.slicer.org/t/camera-observer-arguments/7405>\
**Category:** Development\
**Created:** [July 3, 2019, 10:33pm UTC](https://discourse.slicer.org/t/camera-observer-arguments/7405 "2019-07-03T22:33:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [July 3, 2019, 10:33pm UTC](https://discourse.slicer.org/t/camera-observer-arguments/7405/1 "2019-07-03T22:33:20Z")

</div>

I’m trying to add an observer to the camera (and call a function to set a slice plane normal to camera), the function itself works fine but the observer of the camera either states “TypeError: ‘NoneType’ object is not callable” or wrong arguments if i input anything else than vtk.vtkCommand.ModifiedEvent,

Here is the code i’ve tried :

```
#grab reformat widget and green slice
layoutManager = slicer.app.layoutManager()
reformatWidget = slicer.modules.reformat.widgetRepresentation()
targetslice = slicer.app.layoutManager().sliceWidget('Green')
sliceNode = targetslice.mrmlSliceNode()
reformatWidget.setEditedNode(sliceNode,"","")
reformatWidget.setNormalToCamera ()

# Grab camera and cameranode
view = layoutManager.threeDWidget(0).threeDView()
threeDViewNode = view.mrmlViewNode()
cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(threeDViewNode) ##grabs camera NODE
camera = cameraNode.GetCamera()
# function to call
def refresh():
    reformatWidget.setNormalToCamera ()

#set observer <-------problematic part
cameraobserver = camera.AddObserver(vtk.vtkCommand.ModifiedEvent, refresh())
#also tried cameraobserver = camera.AddObserver("ModifiedEvent", refresh())

```

Any suggestions? thanks.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 3, 2019, 11:06pm UTC](https://discourse.slicer.org/t/camera-observer-arguments/7405/2 "2019-07-03T23:06:18Z")

</div>

I see two syntax errors:

- second argument for Add Observer must be `refresh` or `lambda: refresh()` (and not `refresh()`)
- refresh method must have two arguments (see [this example](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulating_objects_in_the_slice_viewer))

---

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [July 3, 2019, 11:55pm UTC](https://discourse.slicer.org/t/camera-observer-arguments/7405/3 "2019-07-03T23:55:55Z")

</div>

Thanks a lot! i could fix it by doing these modifications:

```
def refresh(param1, param2):
    reformatWidget.setNormalToCamera()
#set observer
cameraobserver = camera.AddObserver(vtk.vtkCommand.ModifiedEvent, refresh, 2)

```

I dont understand why the refresh method needs two arguments though, even if it doesent use them,  
also in this example there is no “,2” at the end (i couldnt make it work without it)

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get\_a\_notification\_if\_a\_markup\_point\_position\_is\_modified](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_a_notification_if_a_markup_point_position_is_modified)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 4, 2019, 12:06am UTC](https://discourse.slicer.org/t/camera-observer-arguments/7405/4 "2019-07-04T00:06:02Z")

</div>

`AddObserver` requires a callback function that can receive event id and caller parameters (and optionally an additional eventdata), regardless if you use this information in the callback function or not.

The third parameter of `AddObserver` is the event priority. It is optional, default value is 0.0.

---

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [July 4, 2019, 12:42am UTC](https://discourse.slicer.org/t/camera-observer-arguments/7405/5 "2019-07-04T00:42:37Z")

</div>

Understood, thanks for your help!
