# How to pass parameter to vtkCommand and subclasses the "eventId" and "callData" parameter?

**URL:** https://discourse.vtk.org/t/how-to-pass-parameter-to-vtkcommand-and-subclasses-the-eventid-and-calldata-parameter/4476
**Category:** Support
**Created:** [October 23, 2020, 9:03am UTC](https://discourse.vtk.org/t/how-to-pass-parameter-to-vtkcommand-and-subclasses-the-eventid-and-calldata-parameter/4476 "2020-10-23T09:03:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![wulicheng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wulicheng/32/1990_2.png) [@wulicheng](https://discourse.vtk.org/u/wulicheng)
#### Post date: [October 23, 2020, 9:03am UTC](https://discourse.vtk.org/t/how-to-pass-parameter-to-vtkcommand-and-subclasses-the-eventid-and-calldata-parameter/4476/1 "2020-10-23T09:03:58Z")

</div>

#include \<vtkSmartPointer.h\>  
#include \<vtkObjectFactory.h\>  
#include \<vtkSphereSource.h\>  
#include \<vtkPolyDataMapper.h\>  
#include \<vtkActor.h\>  
#include \<vtkRenderWindow.h\>  
#include \<vtkRenderer.h\>  
#include \<vtkRenderWindowInteractor.h\>  
#include \<vtkCommand.h\>

class CommandSubclass2 : public vtkCommand  
{  
public:  
vtkTypeMacro(CommandSubclass2, vtkCommand);

```
static CommandSubclass2 *New()
{
  return new CommandSubclass2;
}

void Execute(vtkObject *vtkNotUsed(caller), unsigned long vtkNotUsed(eventId), 
                    void *vtkNotUsed(callData))
{
  std::cout << "timer callback" << std::endl;
}

```

};

int main(int, char \*[])  
{  
// Create a sphere  
vtkSmartPointer sphereSource =  
vtkSmartPointer::New();  
sphereSource-\>Update();

// Create a mapper and actor  
vtkSmartPointer mapper =  
vtkSmartPointer::New();  
mapper-\>SetInputConnection(sphereSource-\>GetOutputPort());  
vtkSmartPointer actor =  
vtkSmartPointer::New();  
actor-\>SetMapper(mapper);

// Create a renderer, render window, and interactor  
vtkSmartPointer renderer =  
vtkSmartPointer::New();  
vtkSmartPointer renderWindow =  
vtkSmartPointer::New();  
renderWindow-\>AddRenderer(renderer);  
vtkSmartPointer renderWindowInteractor =  
vtkSmartPointer::New();  
renderWindowInteractor-\>SetRenderWindow(renderWindow);

// Initialize must be called prior to creating timer events.  
renderWindowInteractor-\>Initialize();  
renderWindowInteractor-\>CreateRepeatingTimer(500);

vtkSmartPointer timerCallback =  
vtkSmartPointer::New();  
renderWindowInteractor-\>AddObserver ( vtkCommand::TimerEvent, timerCallback );

// Add the actor to the scene  
renderer-\>AddActor(actor);  
renderer-\>SetBackground(1,1,1); // Background color white

// Render and interact  
renderWindow-\>Render();  
renderWindowInteractor-\>Start();

return EXIT\_SUCCESS;  
}  
the code is like this, But I don’t know how to pass parameter to eventId and callData?  
[https://lorensen.github.io/VTKExamples/site/Cxx/Utilities/CommandSubclass/](https://lorensen.github.io/VTKExamples/site/Cxx/Utilities/CommandSubclass/)

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [October 24, 2020, 7:56pm UTC](https://discourse.vtk.org/t/how-to-pass-parameter-to-vtkcommand-and-subclasses-the-eventid-and-calldata-parameter/4476/2 "2020-10-24T19:56:46Z")

</div>

Look at these examples:

- [CallBack](https://ajpmaclean.github.io/web-test/site/Cxx/Interaction/CallBack/)
- [KeypressObserver](https://ajpmaclean.github.io/web-test/site/Cxx/Interaction/KeypressObserver/)
- [CallData](https://ajpmaclean.github.io/web-test/site/Cxx/Interaction/CallData/)
