# Python script throws errors when trying to create a cone

**URL:** https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857
**Category:** ParaView Support
**Tags:** python
**Created:** [March 21, 2020, 2:08am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857 "2020-03-21T02:08:03Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![braddeibert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@braddeibert](https://discourse.paraview.org/u/braddeibert)
#### Post date: [March 21, 2020, 2:08am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/1 "2020-03-21T02:08:03Z")

</div>

Hello all.

I am attempting to create a script to automate placing numerous cones into a paraview scene for me. I have run into issues with the following code block:

```
tree = Cone()
tree.Center = treeCenter.split(',')
tree.Radius = treeRadius
tree.Height = treeHeight
tree.Direction = 0,0,1

```

I get type errors from this code, which do not still occur if I instead manually type the data into the paraview GUI python shell.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [March 21, 2020, 2:12am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/2 "2020-03-21T02:12:15Z")

</div>

Do you have an example of the error that occurs?

Cc: @mwestphal

---

<div class="post-metadata">

### Author: ![braddeibert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@braddeibert](https://discourse.paraview.org/u/braddeibert)
#### Post date: [March 21, 2020, 2:14am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/3 "2020-03-21T02:14:17Z")

</div>

Yes. The whole error reads like this:

```
Traceback (most recent call last):
  File "<string>", line 37, in <module>
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 489, in __setattr__
    setter(self, value)
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 2626, in setProperty
    return self.SetPropertyWithName(propName, value)
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 357, in SetPropertyWithName
    prop.SetData(arg)
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 863, in SetData
    self.SMProperty.SetElement(idx, val)
TypeError: SetElement argument 2:
```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [March 21, 2020, 2:15am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/4 "2020-03-21T02:15:39Z")

</div>

I think there’s just one line missing yet 🙂 . What’s the full `TypeError` block?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [March 21, 2020, 2:16am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/5 "2020-03-21T02:16:46Z")

</div>

Oh, I suspect it is your `treeCenter.split(',')` line. That is a list of strings rather than a list/tuple of integers as I expect `Center` probably wants. Does `map(int, treeCenter.split(','))` work?

---

<div class="post-metadata">

### Author: ![braddeibert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@braddeibert](https://discourse.paraview.org/u/braddeibert)
#### Post date: [March 21, 2020, 2:23am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/6 "2020-03-21T02:23:27Z")

</div>

Tested that out, got a different error, but on the line prior. I should’ve mentioned that line 36 is the `treeCenter.split(',')` line.

```
File "<string>", line 36, in <module>
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 489, in __setattr__
    setter(self, value)
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 2626, in setProperty
    return self.SetPropertyWithName(propName, value)
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 357, in SetPropertyWithName
    prop.SetData(arg)
  File "/home/brad/ParaView/lib/python3.7/site-packages/paraview/servermanager.py", line 846, in SetData
    if not self.GetRepeatable() and len(values) != self.GetNumberOfElements():
TypeError: object of type 'map' has no len()
```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [March 21, 2020, 2:27am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/7 "2020-03-21T02:27:08Z")

</div>

Right, Python3 made those iterables. Wrap the `map()` call with `tuple()`.

---

<div class="post-metadata">

### Author: ![braddeibert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@braddeibert](https://discourse.paraview.org/u/braddeibert)
#### Post date: [March 21, 2020, 2:35am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/8 "2020-03-21T02:35:36Z")

</div>

Oh I see! Forgive me, I’m not the most familiar with python.

---

<div class="post-metadata">

### Author: ![braddeibert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@braddeibert](https://discourse.paraview.org/u/braddeibert)
#### Post date: [March 21, 2020, 2:51am UTC](https://discourse.paraview.org/t/python-script-throws-errors-when-trying-to-create-a-cone/3857/9 "2020-03-21T02:51:42Z")

</div>

That appears to have worked! Cheers, Ben!!!
