There's a bug in 3.8.0 in OpenDataFile() which will be fixed in 3.8.1
(already fixed in release branch). Use the attached script as a
sample. It has a newer fixed version of OpenDataFile().

The second sample you used was incorrect since you are mixing
VTK-python  scripting with ParaView's python scripting.

Utkarsh




On Thu, Jul 15, 2010 at 9:00 AM, llapis Pencil <llapispen...@yahoo.es> wrote:
> Hi once again,
>
> I still haven't achieve to open the *.vtk file with a python script. I tried
> mainly two different ways:
>
> 1. Has you said, with the OpenDataFile command. But I get the error below,
> as it could not read *.vtk file.
>
> #Python script
> from paraview.simple import *
> reader = OpenDataFile("C:/Documents and
> Settings/Nit@/Escritorio/pet/out1-1.vtk")
> Show(reader)
> Render()
> ##########
>
> #error on the python shell
> Traceback (most recent call last):
>
> File "<string>", line 2, in <module>
>
> File "C:\Archivos de programa\ParaView
> 3.8.0\lib\paraview-3.8\paraview\simple.py", line 115, in OpenDataFile
>
> reader = globals()[xml_name](FileName=filename, **extraArgs)
>
> File "C:\Archivos de programa\ParaView
> 3.8.0\lib\paraview-3.8\paraview\simple.py", line 542, in CreateObject
>
> setattr(px, param, params[param])
>
> File "C:\Archivos de programa\ParaView
> 3.8.0\lib\paraview-3.8\paraview\servermanager.py", line 201, in __setattr__
>
> "to add this attribute.")
>
> AttributeError: Attribute FileName does not exist. This class does not allow
> addition of new attributes to avoid mistakes due to typos. Use
> add_attribute() if you really want to add this attribute.
>
> ##########
>
> Do someone know what should I change or what 's wrong?
>
> 2. I searched for a specific vtk reader and I found in internet
> (https://visualization.hpc.mil/wiki/VTK_in_Python) the following solution
> and getting the following error:
>
> #python script
> from vtk import *;
> reader = vtkDataSetReader()
> reader.SetFileName("out1-1.vtk")
> Show(reader4)
> Render()
> ###########
>
> #error on the python shell
> Traceback (most recent call last):
>
> File "<string>", line 1, in <module>
>
> ImportError: No module named vtk
>
> ###########
>
> I download the vtk source http://www.vtk.org/VTK/resources/software.html and
> installed the latest verion for Windows. If I had not understood bad I made
> what was necessary
> (https://visualization.hpc.mil/wiki/Getting_Started_with_VTK).
>
> But still doesn't recognize the vtk library. Does someone know what's wrong?
> or how paraview could recognize the vtk library?
>
> Thanks you for advance and sorry for the inconviniences.
>
> Llapis
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
>
>
from paraview.simple import *

def OpenDataFile(filename, **extraArgs):
    """Creates a reader to read the give file, if possible.
       This uses extension matching to determine the best reader possible.
       If a reader cannot be identified, then this returns None."""
    reader_factor = servermanager.ProxyManager().GetReaderFactory()
    if  reader_factor.GetNumberOfRegisteredPrototypes() == 0:
      reader_factor.RegisterPrototypes("sources")
    cid = servermanager.ActiveConnection.ID
    if not reader_factor.TestFileReadability(filename, cid):
        raise RuntimeError, "File not readable: %s " % filename
    if not reader_factor.CanReadFile(filename, cid):
        raise RuntimeError, "File not readable. No reader found for '%s' " % filename
    prototype = servermanager.ProxyManager().GetPrototypeProxy(
      reader_factor.GetReaderGroup(), reader_factor.GetReaderName())
    xml_name = paraview.make_name_valid(prototype.GetXMLLabel())
    if prototype.GetProperty("FileNames"):
      reader = globals()[xml_name](FileNames=filename, **extraArgs)
    else :
      reader = globals()[xml_name](FileName=filename, **extraArgs)
    return reader


OpenDataFile("/tmp/foo.vtk")
Show()
Render()

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to