# How to Edit line width/thickness from line generated from vtk polydata?

**URL:** <https://discourse.slicer.org/t/how-to-edit-line-width-thickness-from-line-generated-from-vtk-polydata/25380>\
**Category:** Development\
**Created:** [September 21, 2022, 8:37pm UTC](https://discourse.slicer.org/t/how-to-edit-line-width-thickness-from-line-generated-from-vtk-polydata/25380 "2022-09-21T20:37:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_Zhang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jack_zhang/32/16328_2.png) [@Jack\_Zhang](https://discourse.slicer.org/u/Jack_Zhang)\
**Post date:** [September 21, 2022, 8:37pm UTC](https://discourse.slicer.org/t/how-to-edit-line-width-thickness-from-line-generated-from-vtk-polydata/25380/1 "2022-09-21T20:37:34Z")

</div>

Operating system: Windows 10  
Slicer version: 5.0.3

I’m trying to code a python extension that plots a line using points read from a csv file. After creating the script to add the required values to a vtkPoints and vtkPolyLine objects, I was able to render the line using the following:

```auto
# Create a polydata to store everything in
polyData = vtk.vtkPolyData()

# Add the points to the dataset
polyData.SetPoints(points)

# Add the lines to the dataset
polyData.SetLines(cells)

slicer.modules.models.logic().AddModel(polyData)

```

Output:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/b/7bd810f6bd6efe1ea8fb3873e7603cf91d46abb5.png)

I now want to edit the line thickness.

When I use vtk outside of slicer, I would just use the following:

```auto
# Setup actor and mapper
mapper = vtkPolyDataMapper()
mapper.SetInputData(polyData)

actor = vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetLineWidth(5)

# Setup render window, renderer, and interactor
renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.SetWindowName('PolyLine')
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderer.AddActor(actor)
renderWindow.Render()
renderWindowInteractor.Start()

```

However, I’m not sure how to use actor and renderer with Slicer. Is there a way of using actors in a Slicer scene?

I know the _Models_ module’s UI has a line width slider, so I’m probably just missing something. I’ve tried looking in the logic file for the _Models_ module, but haven’t found anything I can use. Any help at all would be appreciated.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 21, 2022, 8:49pm UTC](https://discourse.slicer.org/t/how-to-edit-line-width-thickness-from-line-generated-from-vtk-polydata/25380/2 "2022-09-21T20:49:08Z")

</div>

Slicer uses. concept called a “displayable manager”. You can search the code and this forum for `MRMLDM` and find discussions. This is the part of the code that manages mapping from the MRML scene to the mappers/actors at the vtk rendering system level.

---

<div class="post-metadata">

**Author:** ![Jack\_Zhang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jack_zhang/32/16328_2.png) [@Jack\_Zhang](https://discourse.slicer.org/u/Jack_Zhang)\
**Post date:** [September 21, 2022, 8:49pm UTC](https://discourse.slicer.org/t/how-to-edit-line-width-thickness-from-line-generated-from-vtk-polydata/25380/3 "2022-09-21T20:49:57Z")

</div>

Thanks I’ll give that a try.

---

<div class="post-metadata">

**Author:** ![Jack\_Zhang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jack_zhang/32/16328_2.png) [@Jack\_Zhang](https://discourse.slicer.org/u/Jack_Zhang)\
**Post date:** [September 22, 2022, 3:19pm UTC](https://discourse.slicer.org/t/how-to-edit-line-width-thickness-from-line-generated-from-vtk-polydata/25380/4 "2022-09-22T15:19:43Z")

</div>

I found the solution. I used the following code to get the actor being used by the 3D renderer and then modify its line width property.

```auto
# Get renderer actor
actor = slicer.app.layoutManager().activeThreeDRenderer().GetActors().GetLastActor()

# Adjust line width property
actorProperty = actor.GetProperty()
actorProperty.SetLineWidth(3)

```
