# Python code to place fiducial markers into slicer

**URL:** https://discourse.slicer.org/t/python-code-to-place-fiducial-markers-into-slicer/24317
**Category:** Support
**Tags:** python
**Created:** [July 14, 2022, 3:51pm UTC](https://discourse.slicer.org/t/python-code-to-place-fiducial-markers-into-slicer/24317 "2022-07-14T15:51:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mxtt](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@mxtt](https://discourse.slicer.org/u/mxtt)
#### Post date: [July 14, 2022, 3:51pm UTC](https://discourse.slicer.org/t/python-code-to-place-fiducial-markers-into-slicer/24317/1 "2022-07-14T15:51:24Z")

</div>

I am trying to place fiducial markers down, but not with the widget or GUI. I am wondering how I can do this in my python code. I have a text file with a list of coordinates, and I want to place the markers at those coordinates. Any help would be appreciated. Thanks.

---

<div class="post-metadata">

### Author: ![mangotee](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@mangotee](https://discourse.slicer.org/u/mangotee)
#### Post date: [July 14, 2022, 4:17pm UTC](https://discourse.slicer.org/t/python-code-to-place-fiducial-markers-into-slicer/24317/2 "2022-07-14T16:17:02Z")

</div>

Here’s one way to do it: Read your text file into a Nx3 numpy array (here: `arr`), then create or get the desired fiducial node (here: `nfids`, class: `slicer.vtkMRMLMarkupsFiducialNode`). With these two, you can use the following function to place fiducials into that node (with or without names):

```python
def fiducialListFromArray(nfids, arr, listFidNames=None):
    nrfids = arr.shape[0]
    if listFidNames is None:
        listFidNames = ['%s-%d'%(nfids.GetName(),i+1) for i in range(nrfids)]
    for i in range(nrfids):
        nfids.AddFiducial(arr[i,0], arr[i,1], arr[i,2], listFidNames[i])
    return nfids

```

---

<div class="post-metadata">

### Author: ![mxtt](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@mxtt](https://discourse.slicer.org/u/mxtt)
#### Post date: [July 14, 2022, 4:28pm UTC](https://discourse.slicer.org/t/python-code-to-place-fiducial-markers-into-slicer/24317/3 "2022-07-14T16:28:15Z")

</div>

```python
slicer.modules.markups.logic().AddFiducial(x, y, z)

```

I think this will work right?

---

<div class="post-metadata">

### Author: ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)
#### Post date: [July 15, 2022, 4:49pm UTC](https://discourse.slicer.org/t/python-code-to-place-fiducial-markers-into-slicer/24317/4 "2022-07-15T16:49:18Z")

</div>

@mxtt Reading the `Markups` section of the “Script Repository” should help you move forward:  
[https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#markups](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#markups)

> place fiducial markers down, but not with the widget or GUI. […] do this in my python code

More specifically, the entry [Adding control points Programmatically](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#adding-control-points-programmatically)
