Python script throws errors when trying to create a cone

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.

Do you have an example of the error that occurs?

Cc: @mwestphal

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:

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

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?

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()

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

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

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