[Paraview] Use of Python declared variables inside new scripts from ProgrammableSource and/or ProgrammableFilter.

Guillaume Jacquenot guillaume.jacquenot at gmail.com
Mon Jan 18 09:35:03 EST 2016


Hello everyone,

Thanks Utkarsh for this answer.
It works with pvpython.
Unfortunately, this does not work with paraview
I have tested manually from a desktop version of Paraview, with Paraview
4.4 and 5.0 on Windows.
I have this error:
NameError: global name 'meta_data' is not defined

In fact, I have found another solution to do what I want from Paraview
I declare the new variables as member in the RequestInformationScript
(self.data=12) and I use them in the Script (print(self.data))
However,this has some drawbacks. When I update the paraview tree, eg I
update the size of an unrelated glyph, the value changes, and consequently
breaks my scene

Moreover, when I test it with pvpython, it clearly tells me that it is not
from paraview.simple import ProgrammableSource
from paraview.simple import UpdatePipeline

>>> p = ProgrammableSource();p.Script =
'print(self.x)';p.RequestInformationScript = 'self.x=12';UpdatePipeline()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ParaView
5.0.0\lib\paraview-5.0\site-packages\paraview\servermanager.py", line 302,
in __setattr__    "to add this attribute.")
AttributeError: Attribute RequestInformationScript 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.

p = ProgrammableSource();p.Script =
'print(self.x)';p.add_attribute('x',12);UpdatePipeline()
But, how to use this attribute?
May be I need to play with parameters?


This finds some echoes here, where apparently the only solution proposed is
to ascii write the data to pass to the script.
https://cmake.org/pipermail/paraview/2013-May/028291.html
This is clearly not a solution for me.


2016-01-04 20:22 GMT+01:00 Utkarsh Ayachit <utkarsh.ayachit at kitware.com>:

> The following works in builtin (non-remote server) mode only.
>
> global meta_data
> meta_data =12
>
> p = ProgrammableSource()
> p.Script="""
> global meta_data
> print meta_data
> """
>
> UpdatePipeline()
>
> --------------------------------------------
> Output:
> --------------------------------------------
> 12
>
> Utkarsh
>
> On Wed, Dec 30, 2015 at 9:03 AM, Guillaume Jacquenot
> <guillaume.jacquenot at gmail.com> wrote:
> > I would like to use Python declared variables inside new scripts from
> > ProgrammableSource and/or ProgrammableFilter.
> >
> > Why do I want such a thing? I could simply declared these variables in
> the
> > code of the script.
> > But what if these variables are to be used by several scripts from
> > ProgrammableSource and/or ProgrammableFilter?
> >
> > Of course, I can serialize variables and pass the serialized data to the
> > scripts, taking special care for float. But, what if I have large data,
> that
> > are difficult to serialize?
> >
> > So, here is my question:
> > Is there a mechanism to access already defined data inside the scripts of
> > ProgrammableSource and/or ProgrammableFilter? For example, a global scope
> > dict?
> > Do I have to use an external file to store and access data?
> > Below is the example of the Python file I would like to run , where I
> have
> > defined a 'data' that I want to access inside the script. If I try to
> > directly access 'data', I have a "NameError: global name 'data' is not
> > defined"
> >
> > My data are in fact transformation matrices that will be used to move
> > objects from a ProgrammableFilter. Using the Animation Keyframes are
> > terribly slow.
> >
> > Guillaume
> >
> >
> >
> > Python script:
> >
> >     data = ....
> >
> >     script="""
> >     instructions to access "data" at run time
> >     ...
> >     """
> >
> >     scriptRequestInformation="""
> >     ...
> >     """
> >
> >     source = ProgrammableSource()
> >     source.OutputDataSetType = 'vtkStructuredGrid'
> >     source.Script = script
> >     source.ScriptRequestInformation = scriptRequestInformation
> >     source.PythonPath = ''
> >
> > _______________________________________________
> > 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
> >
> > Search the list archives at: http://markmail.org/search/?q=ParaView
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/paraview
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20160118/fd870036/attachment.html>


More information about the ParaView mailing list