[Paraview] programmable filter in a python script
Utkarsh Ayachit
utkarsh.ayachit at kitware.com
Wed Nov 27 14:21:22 EST 2013
Joe,
Note you can use """ .... """ in Python for strings with new lines,
that way you don't have to escape anything.
Utkarsh
On Wed, Nov 27, 2013 at 2:18 PM, joseph insley <insley at anl.gov> wrote:
> Thanks, Utkarsh,
>
> Yeah, I figured out the part about passing the needed variables as arguments last night. The next problem that I ran into was that from within my script I create vtk objects (vtk.vtkCutter() for example). Of course in the scope of my new script, vtk is not defined. I tried importing it, but that proved to be less than trivial. I know that ParaView uses its own vtk, so I tried adding the path to ParaView's site-packages (and various subdirectories) to PYTHONPATH, but it still had trouble finding some needed modules (vtkCommonCorePython, was the last one I encountered). So, I bailed out on trying to import my code as a separate script, and instead resorted to leaving it all inline, but using the '\' character after every \n in order to split the string across multiple lines. It is not the most ideal solution, but it at least makes the code readable/manageable.
>
> Thanks again for your help,
> joe
>
> On Nov 27, 2013, at 7:56 AM, Utkarsh Ayachit wrote:
>
>> Joe,
>>
>> YOu can put your script in a function with arguments in the foo.py
>> file and then call that function with the inputs argument passed in
>> from the small script in the Programmable filter.
>>
>> Utkarsh
>>
>> On Tue, Nov 26, 2013 at 5:47 PM, joseph insley <insley at anl.gov> wrote:
>>> Thanks for the pointers.
>>>
>>> Another naive follow up question..
>>>
>>> The script of my programmable filter starts with:
>>> input = inputs[0]
>>>
>>> This works fine when the script is defined inline, but when I import it from an external file, inputs is not defined. How do I get around this?
>>>
>>> Thanks,
>>> joe
>>>
>>> On Nov 26, 2013, at 2:55 PM, Felipe Bordeu Weldt wrote:
>>>
>>>> or you can use the execfile('myfiltersource.py') instruction of python, and you put all you filter's code in the file.
>>>>
>>>>
>>>>
>>>> Le 26 nov. 13 à 21:03, Utkarsh Ayachit a écrit :
>>>>
>>>>>> my question is, can I create the script of the Programmable filter as a separate python script, and then just give the Programmable filter the path to this external python script?
>>>>>
>>>>> Yup, you indeed can. In fact, the programmable filter/source also has
>>>>> a property named "PythonPath" that you can set to the location where
>>>>> you'll have the python script you want to import in the filter code
>>>>> (you may have to put the path in quotes). State file attached. It will
>>>>> import foo in the Python programmable source when foo.py is put in
>>>>> /tmp.
>>>>>
>>>>> Utkarsh
>>>>> <foo.py><sample.pvsm>_______________________________________________
>>>>> 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
>>>>
>>>> _______________________________________________
>>>> 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
>>>
>>> _______________________________________________
>>> 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
>
More information about the ParaView
mailing list