[Paraview] pvpython pass string to Script (Programmable Source)

Mauro Fontana fontana.mauro at gmail.com
Thu Mar 2 11:25:41 EST 2017


Now that sounds (reads) much better and cleaner.

Thanks for your time and your response David.

Cheers

On Thu, Mar 2, 2017 at 1:06 PM David E DeMarle <dave.demarle at kitware.com>
wrote:

> Use the hidden property called Parameters on the Python Filter/Source to
> pass in information.
>
> >>> prosrc = ProgrammableSource()
>
> >>> prosrc.Script = ("""
>
> ... try:
>
> ...   instring
>
> ... except NameError:
>
> ...   instring = "GOODBYE"
>
> ... print instring
>
> ... """)
>
> >>> prop = prosrc.GetProperty("Parameters")
>
> >>> prop.SetElement(0, "instring")
>
> 1
>
> >>> prop.SetElement(1, "'HELLO'")
>
> 1
>
> >>> prosrc.UpdateProperty("Parameters")
>
> True
>
> >>> prosrc.UpdatePipeline()
>
> HELLO
>
>
>
> David E DeMarle
> Kitware, Inc.
> R&D Engineer
> 21 Corporate Drive
> Clifton Park, NY 12065-8662
> Phone: 518-881-4909 <(518)%20881-4909>
>
> On Wed, Mar 1, 2017 at 3:38 PM, Mauro Fontana <fontana.mauro at gmail.com>
> wrote:
>
> Hello
>
> Sorry to bother, but I can't seem to find a way (in the mailing list or
> the documentation) to pass a string as some kind of argument to
> Programmable Source (using pvpython interpreter). The python "program"
> needs to load a custom binary format using numpy.fromfile.
>
> What I've thought is to write a wrapper function. The function should
> receive a string as argument and then instantiate a programmable filter and
> execute
> myscript.replace(random_var_name, myfilename)
> MyProgrammableSource.Script = myscript
> return MyProgrammableSource
>
> Where random_var_name is the argument of my numpy.fromfile call. But that
> doesn't seem very "pythonic". Is there a way to pass a string to the Script
> without the .replace hack?
>
> Sorry if this is documented, I couldn't find it.
>
> Cheers,
> Mauro
>
> _______________________________________________
> 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/20170302/aeaaf2db/attachment.html>


More information about the ParaView mailing list