# How to fix a custom VTK reader?

**URL:** https://discourse.paraview.org/t/how-to-fix-a-custom-vtk-reader/2586
**Category:** ParaView Support
**Created:** [September 19, 2019, 9:58am UTC](https://discourse.paraview.org/t/how-to-fix-a-custom-vtk-reader/2586 "2019-09-19T09:58:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![newbee](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/n/5f8ce5/32.png) [@newbee](https://discourse.paraview.org/u/newbee)
#### Post date: [September 19, 2019, 9:58am UTC](https://discourse.paraview.org/t/how-to-fix-a-custom-vtk-reader/2586/1 "2019-09-19T09:58:08Z")

</div>

Hi, I’m a beginner of paraview, and now I’m developing a custom reader.  
My paraview version is 3.14, so I followed this example: [https://vtk.org/Wiki/ParaView/Examples/Plugins/Reader](https://vtk.org/Wiki/ParaView/Examples/Plugins/Reader)

After plugin loaded, I found RequestData not called.  
I tried these things:  
Draw a single point instead of reading file, show nothing;  
Call RequestData in RequestInformation, now output has value, bu still show nothing.  
Where is my mistake?  
Here is part of my code:

```
class VTK_EXPORT SimworksGridReader : public vtkUnstructuredGridAlgorithm
{
public:
  static SimworksGridReader *New();
  vtkTypeMacro(SimworksGridReader,vtkUnstructuredGridAlgorithm);
  void PrintSelf(ostream& os, vtkIndent indent);
  vtkSetStringMacro(FileName);
  vtkGetStringMacro(FileName);
  // Description:
  // Get the output of this reader.
  vtkUnstructuredGrid *GetOutput();
  vtkUnstructuredGrid *GetOutput(int idx);
  void SetOutput(vtkUnstructuredGrid *output);
  
protected:
  SimworksGridReader();
  ~SimworksGridReader();

  virtual int RequestData(vtkInformation *, vtkInformationVector **,
                          vtkInformationVector *);
  virtual int RequestInformation(vtkInformation* request,
      vtkInformationVector** inputVector,
      vtkInformationVector* outputVector);

  virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **,
                                  vtkInformationVector *);
  
  virtual int FillOutputPortInformation(int, vtkInformation*);
private:
  SimworksGridReader(const SimworksGridReader&); // Not implemented.
  void operator=(const SimworksGridReader&); // Not implemented.
  char* FileName;
};

int SimworksGridReader::FillOutputPortInformation(int,
    vtkInformation* info)
{
    info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid"); 
    info->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(), -1);
    return 1;
}

int SimworksGridReader::RequestInformation(vtkInformation* request,
    vtkInformationVector** inputVector,
    vtkInformationVector* outputVector)
{
    vtkInformation* info = outputVector->GetInformationObject(0);
    return 1;
}

int SimworksGridReader::RequestData(
  vtkInformation *request,
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
{
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
  int size, ncells=0;
  vtkCellArray *cells=NULL;
  int *types=NULL;
  vtkIdType *idArray;

  vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));

  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  points->InsertNextPoint(0,0,0);
  output->SetPoints(points);
  cells = vtkCellArray::New();
  ncells = 1;
  size =1;
  idArray = cells->WritePointer(ncells, size);
  idArray[0] = 0;
  types = new int[ncells];
  types[0] = 1;
  output->SetCells(types, cells);
  return 1;
}

```

Thanks in advance.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 20, 2019, 12:49am UTC](https://discourse.paraview.org/t/how-to-fix-a-custom-vtk-reader/2586/2 "2019-09-20T00:49:41Z")

</div>

Does the example you linked works for you ?

---

<div class="post-metadata">

### Author: ![newbee](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/n/5f8ce5/32.png) [@newbee](https://discourse.paraview.org/u/newbee)
#### Post date: [September 20, 2019, 10:46am UTC](https://discourse.paraview.org/t/how-to-fix-a-custom-vtk-reader/2586/3 "2019-09-20T10:46:20Z")

</div>

Thanks! I tried the example exactly, after that I found i was misled by later version. In version 3.14, RequestData is called after user press “Apply” button, while later version will show the grid immediately. Now the problem is solved.
