<div dir="ltr">Hi George,<div><br></div><div>In your example you are only defining a single face and I am pretty sure that a polyhedron requires a closed / "watertight" volume by definition. </div><div><div><br></div><div>I am using vtk 5.10.1 with python 2.7 and the following example works for me (translation of C++ example Bill posted above). </div><div><br></div><div><div>Code:</div><div><div>  import vtk</div><div>  # Create polyhedron (cube)</div><div>  pointIds = vtk.vtkIdList()</div><div>  pointIds.SetNumberOfIds(8)</div><div>  for i in range(8):</div><div>    pointIds.InsertNextId(i)</div><div>  points = vtk.vtkPoints()</div><div>  points.InsertNextPoint(-1.0,-1.0,-1.0)</div><div>  points.InsertNextPoint( 1.0,-1.0,-1.0)</div><div>  points.InsertNextPoint( 1.0, 1.0,-1.0)</div><div>  points.InsertNextPoint(-1.0, 1.0,-1.0)</div><div>  points.InsertNextPoint(-1.0,-1.0, 1.0)</div><div>  points.InsertNextPoint( 1.0,-1.0, 1.0)</div><div>  points.InsertNextPoint( 1.0, 1.0, 1.0)</div><div>  points.InsertNextPoint(-1.0, 1.0, 1.0)</div><div><br></div><div>  # List of pointIds that make up the face</div><div>  faceList = [[0, 3, 2, 1],[0, 4, 7, 3],[4, 5, 6, 7],[5, 1, 2, 6],[0, 1, 5, 4],[2, 3, 7, 6]]</div><div>  faceId = vtk.vtkIdList()</div><div>  faceId.InsertNextId(6) # Number faces that make up the cell.</div><div>  for face in faceList: # Loop over all the faces</div><div>    faceId.InsertNextId(len(face)) # Number of points in face</div><div>    [faceId.InsertNextId(i) for i in face] # Insert the pointIds for the face</div><div><br></div><div><br></div><div>  ugrid = vtk.vtkUnstructuredGrid()</div><div>  ugrid.SetPoints(points)</div><div>  ugrid.InsertNextCell(vtk.VTK_POLYHEDRON, faceId)</div><div><br></div><div>  writer = vtk.vtkXMLUnstructuredGridWriter()</div><div>  writer.SetInput(ugrid)</div><div>  writer.SetFileName("polyhedron.vtu")</div><div>  writer.SetDataModeToAscii()</div><div>  writer.Update()</div></div></div><div>Code ends</div><div><br></div><div>The main difference is that the ugrid.InsertNextCells takes 2 arguments: type of cell and the vtkIdList of point Ids that make up the cell. For polyhedrons, the IdList has to contain information about the number faces that make up the cell and then the point Ids of the the faces. </div></div><div><br></div><div>I hope this helps,</div><div>Gudni </div></div><div class="gmail_extra"><br><div class="gmail_quote">On 2 November 2014 13:33, George <span dir="ltr"><<a href="mailto:george.gerber@gmail.com" target="_blank">george.gerber@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Good day,<br>
<br>
I have translated the example of Bill into the best Python I know. I get the<br>
following error:<br>
Traceback (most recent call last):<br>
  File "C:\Users\george limited\Desktop\unstructuredgrid.py", line 19, in<br>
<module><br>
    ug.InsertNextCell(vtk.VTK_POLYHEDRON,4,pointids,1,faces)<br>
TypeError: InsertNextCell argument 5: expected a sequence of 0 values, got<br>
vtkobject<br>
<br>
Any advice will be very much appreciated.<br>
Best regards,<br>
George<br>
<br>
The code is:<br>
import vtk<br>
<br>
points = vtk.vtkPoints()<br>
pointids = [0,1,2,3]<br>
<br>
points.InsertNextPoint(0,0,0)<br>
points.InsertNextPoint(1,0,0)<br>
points.InsertNextPoint(1,1,0)<br>
points.InsertNextPoint(0,1,0)<br>
<br>
faces = vtk.vtkCellArray()<br>
<br>
face0 = [0,1,2,3]<br>
<br>
faces.InsertNextCell(4,face0)<br>
<br>
ug = vtk.vtkUnstructuredGrid()<br>
ug.SetPoints(points)<br>
ug.InsertNextCell(vtk.VTK_POLYHEDRON,4,pointids,1,faces.GetPointer())<br>
<span class=""><br>
writer = vtk.vtkUnstructuredGridWriter()<br>
writer.SetFileName("polyhedron.vtu")<br>
writer.SetInputData(ug)<br>
writer.Write()<br>
<br>
<br>
<br>
--<br>
</span>View this message in context: <a href="http://vtk.1045678.n5.nabble.com/polyhedron-in-python-tp5728643p5729319.html" target="_blank">http://vtk.1045678.n5.nabble.com/polyhedron-in-python-tp5728643p5729319.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div>Gudni Karl Rosenkjaer,</div><div>PhD student at Geophysical Inversion Facility</div><div>Department of Earth, Ocean and Atmospheric Sciences,</div><div>University of British Columbia</div></div>
</div>