# How to define a single scalar as an input parameter for Programmable Filter

**URL:** https://discourse.paraview.org/t/how-to-define-a-single-scalar-as-an-input-parameter-for-programmable-filter/6695
**Category:** ParaView Support
**Created:** [March 14, 2021, 2:59am UTC](https://discourse.paraview.org/t/how-to-define-a-single-scalar-as-an-input-parameter-for-programmable-filter/6695 "2021-03-14T02:59:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![parajan](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/6a8cbe/32.png) [@parajan](https://discourse.paraview.org/u/parajan)
#### Post date: [March 14, 2021, 2:59am UTC](https://discourse.paraview.org/t/how-to-define-a-single-scalar-as-an-input-parameter-for-programmable-filter/6695/1 "2021-03-14T02:59:49Z")

</div>

I would like to create a custom filter consisting of the programmable filter and others. The programmable filter has a hardcoded parameter in it, that I would like to define as an input parameter. Is that possible?

As an example, let’s take the helix code from the tutorials (below). Is it possible to have `length` be an input field for the filter instead of it being hardcoded?

```auto
#This script generates a helix curve.
#This is intended as the script of a 'Programmable Source'
import math

numPts = 80 # Points along Helix
length = 8.0 # Length of Helix
rounds = 3.0 # Number of times around

#Get a vtk.PolyData object for the output
pdo = self.GetPolyDataOutput()

#This will store the points for the Helix
newPts = vtk.vtkPoints()
for i in range(0, numPts):
   #Generate the Points along the Helix
   x = i*length/numPts
   y = math.sin(i*rounds*2*math.pi/numPts)
   z = math.cos(i*rounds*2*math.pi/numPts)
   #Insert the Points into the vtkPoints object
   #The first parameter indicates the reference.
   #value for the point. Here we add them sequentially.
   #Note that the first point is at index 0 (not 1).
   newPts.InsertPoint(i, x,y,z)

#Add the points to the vtkPolyData object
#Right now the points are not associated with a line - 
#it is just a set of unconnected points. We need to
#create a 'cell' object that ties points together
#to make a curve (in this case). This is done below.
#A 'cell' is just an object that tells how points are
#connected to make a 1D, 2D, or 3D object.
pdo.SetPoints(newPts)

#Make a vtkPolyLine which holds the info necessary
#to create a curve composed of line segments. This
#really just hold constructor data that will be passed
#to vtkPolyData to add a new line.
aPolyLine = vtk.vtkPolyLine()

#Indicate the number of points along the line
aPolyLine.GetPointIds().SetNumberOfIds(numPts)
for i in range(0,numPts):
   #Add the points to the line. The first value indicates
   #the order of the point on the line. The second value
   #is a reference to a point in a vtkPoints object. Depends
   #on the order that Points were added to vtkPoints object.
   #Note that this will not be associated with actual points
   #until it is added to a vtkPolyData object which holds a
   #vtkPoints object.
   aPolyLine.GetPointIds().SetId(i, i)

#Allocate the number of 'cells' that will be added. We are just
#adding one vtkPolyLine 'cell' to the vtkPolyData object.
pdo.Allocate(1, 1)

#Add the poly line 'cell' to the vtkPolyData object.
pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())

#The Helix is ready to plot! Click 'Apply'.

```

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/danlipsa/32/1563_2.png) [@danlipsa](https://discourse.paraview.org/u/danlipsa)
#### Post date: [March 15, 2021, 1:00pm UTC](https://discourse.paraview.org/t/how-to-define-a-single-scalar-as-an-input-parameter-for-programmable-filter/6695/2 "2021-03-15T13:00:06Z")

</div>

Yes, it is possible. But you’ll have to write your slightly differently using the PythonAlgorithm. This will allow you to add parameters and gui interface to your algorithm.

See  
[https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html](https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html)

section 4.4 Python Algorithm.
