Hi,<div><br></div><div>I have figured out how to do it now. This post was very useful: <a href="http://www.vtk.org/pipermail/vtkusers/2005-October/082317.html">http://www.vtk.org/pipermail/vtkusers/2005-October/082317.html</a></div>

<div><br></div><div>However, when I run my code, another window pops up saying<b> <font class="Apple-style-span" color="#CC0000">&quot;vtkpython.exe has stopped working&quot;</font></b>.</div><div>Does anyone have any ideas why vtkpython might stop running???</div>

<div><br></div><div>The txt file that I read from has a single line, saying the no. of points, then a list of point info, then single line saying the no. of elements, then a list of elements info.</div><div><br></div><div>

My code in its entirety:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">import vtk<br>from vtk import vtkTriangle <br>VTK_TRIANGLE = vtkTriangle().GetCellType() <br>

<br>with open(&#39;C:\\Qt\\SimLCM\\Default\\Data_Input_Geometry.txt&#39;, &#39;r&#39;) as f:<br>    <br>    aMeshGrid = vtk.vtkUnstructuredGrid()<br>    aMeshGrid.Allocate(2, 180)<br><br>    # Get number of mesh points<br>

    no_points = int(f.readline())<br>    <br>    # Set number of points<br>    meshPoints = vtk.vtkPoints()<br>    meshPoints.SetNumberOfPoints(no_points)<br>    <br>    # Iterate through point data<br>    for i in range(no_points):<br>

        # Get coord info for each point<br>        point_info = f.readline().split() # I need to split, before I assign to point_coord<br>                                          # else the whole thing is split into single numbers<br>

        #print point_info # Check reading<br>        point_ID = (int(point_info[0])-1) # -1 because the IDs need to start with 0.<br>        point_x = float(point_info[1])<br>        point_y = float(point_info[2])<br>        point_z = float(point_info[3])<br>

        #print point_ID, point_x, point_y, point_z<br>        # Set coord info in mesh<br>        meshPoints.InsertPoint(point_ID, point_x, point_y, point_z)<br><br>    # Get number of elements<br>    no_elements = int(f.readline())<br>

    #print &#39;the no_elements&#39;, no_elements<br><br>    # Set number of elements<br>    for i in range(no_elements):<br>        element_info = f.readline().split()<br>        element_ID = (int(element_info[0])-1)<br>

        element_no_nodes = int(element_info[1])<br>        <br>        element_ID_list = vtk.vtkIdList()<br>        for j in range(element_no_nodes):<br>            node_no = int(element_info[j+2])<br>            element_ID_list.InsertNextId(node_no)<br>

            print j, node_no<br>        if element_no_nodes == 3: # a triangle<br>            cell_type = VTK_TRIANGLE<br>            <br>        aMeshGrid.InsertNextCell(cell_type, element_ID_list)<br><br>aMeshGrid.SetPoints(meshPoints)<br>

<br>aMeshMapper = vtk.vtkDataSetMapper()<br>aMeshMapper.SetInput(aMeshGrid)<br><br>aMeshActor = vtk.vtkActor()<br>aMeshActor.SetMapper(aMeshMapper)<br>aMeshActor.GetProperty().SetDiffuseColor(1, 0, 0)<br><br># Create the usual rendering stuff.<br>

ren = vtk.vtkRenderer()<br>renWin = vtk.vtkRenderWindow()<br>renWin.AddRenderer(ren)<br>renWin.SetSize(300, 300)<br>iren = vtk.vtkRenderWindowInteractor()<br>iren.SetRenderWindow(renWin)<br><br>ren.AddActor(aMeshActor)<br>

<br># Zoom, to see actor. (in case it was too small to see)<br>ren.ResetCamera() #<a href="http://www.vtk.org/doc/nightly/html/classvtkRenderer.html#b14d1aeb74a4990f2da819e09d028d65">http://www.vtk.org/doc/nightly/html/classvtkRenderer.html#b14d1aeb74a4990f2da819e09d028d65</a><br>

cam1 = ren.GetActiveCamera()<br>cam1.Zoom(10)<br><br>## Render the scene and start interaction.<br>iren.Initialize()<br>renWin.Render()<br>iren.Start()</blockquote><div><div><div>        </div><div>Help appreciated!</div>

<div><br></div><div>Regards,</div><div>Helvin</div><div><br></div><div><br></div><div class="gmail_quote">On Sun, Aug 23, 2009 at 6:51 PM, Helvin Lui <span dir="ltr">&lt;<a href="mailto:helvinlui@gmail.com">helvinlui@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I&#39;m gonna cry soon if I don&#39;t get this done. &gt; &lt;<div><br></div><div>I have a .txt file of points and connectivity data. How do I read this in as an unstructuredGrid? </div>

<div>How do I use vtkCellArray?</div>
<div><br></div><div>At the moment, I have this:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">with open(&#39;C:\\Qt\\SimLCM\\Default\\Data_Input_Geometry.txt&#39;, &#39;r&#39;) as f:<br>


#with open(&#39;C:\\Qt\\SimLCM\\Default\\Data_Input_Geometry_trial2.txt&#39;, &#39;r&#39;) as f:<br> <br>    meshPoints = vtk.vtkPoints()<br>    # Can&#39;t use voxels, because they specify corners that are perpendicular<br>


    <br>    # Get number of points<br>    no_points = f.readline()<br>    no_points = int(no_points)<br>    print no_points   # Check reading<br>    <br>    # Set number of points in mesh<br>    meshPoints.SetNumberOfPoints(no_points)<br>


    <br>    for i in range(no_points):<br>        # Get coord info for each point<br>        point_info = f.readline().split() # I need to split, before I assign to point_coord<br>                                          # else the whole thing is split into single numbers<br>


        #print point_info # Check reading<br>        <br>        point_ID = (int(point_info[0])-1) # -1 because the IDs need to start with 0.<br>        point_x = float(point_info[1])<br>        point_y = float(point_info[2])<br>


        point_z = float(point_info[3])<br>        print point_ID, point_x, point_y, point_z<br>        # Set coord info in mesh<br>        meshPoints.InsertPoint(point_ID, point_x, point_y, point_z)<br>    <br># Don&#39;t need the input file anymore. Get on with the display<br>


aMeshGrid = vtk.vtkUnstructuredGrid()<br>aMeshGrid.Allocate(180,1)<br><br>cellTypes = vtk.vtkCellTypes()<br>aMeshGrid.InsertNextCell(cellTypes,[1,2,13])<br>aMeshGrid.SetPoints(meshPoints)</blockquote><div><br></div><div>

          etc...</div>
<div><br></div><div>But this second last line gives an error saying: TypeError: An Integer is required. </div><div><br></div><div>PLEASE help!  Please...<br>-- <br>Helvin <br><br>&quot;Though the world may promise me more, I&#39;m just made to be filled with the Lord.&quot;<br>



</div>
</blockquote></div><br><br clear="all"><br>-- <br>Helvin <br><br>&quot;Though the world may promise me more, I&#39;m just made to be filled with the Lord.&quot;<br>
</div></div>