|
[Sponsors] |
October 17, 2015, 18:42 |
import local functions in pvpython
|
#1 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
So I have a script in my working directory which has functions I want to call in to pv python, but for some reason when I call them,
for example Code:
import os os.chdir('pathtomyscript') from script import function Does anyone know why this might be happening and how I can fix the issue? |
|
October 18, 2015, 18:59 |
|
#2 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
If you're in a folder with myscript.py which has a function named myFunction then
Code:
from myscript import myFunction Regards, Mikko |
|
October 18, 2015, 22:19 |
|
#3 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
seems to be working today, I must have been doing something careless yesterday, but now, although I can import the function fine, it isn't recognising the things that I call from paraview.simple. For example currently I am using the following function:
Code:
def clip(): import paraview FluentCaseReader1 = GetActiveSource() Clip1 = Clip( ClipType="Plane" ) Clip1.Scalars = ['POINTS', 'DENSITY'] Clip1.ClipType = "Plane" Clip1.ClipType.Origin = [-0.0454, -0.02, -0.002] Clip1.ClipType.Normal = [0.03, 0.1, 1] return(Clip1) TypeError: clip() takes exactly 1 argument (0 given) which is strange because clip() doesn't take any arguments. Secondly, if I give it an arbitrary argument, say 1 for example, I get FluentCaseReader1 = GetActiveSource() NameError: global name 'GetActiveSource' is not defined also, if I run the script in containing the functions in pv python and then call them they work fine... Any suggestions? Last edited by seanread; October 18, 2015 at 22:33. Reason: update |
|
October 19, 2015, 05:54 |
|
#4 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
The namespaces are somehow confused. Why are you importing paraview in the beginning of your function? Can you try this?
Code:
import myscript import paraview.simple as pv myscript.clip() so = pv.GetActiveSource() pv.Clip(so) |
|
October 19, 2015, 07:17 |
|
#5 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
Code:
>>> PA.clip() Traceback (most recent call last): File "<console>", line 1, in <module> File "/media/sean/data/MASTERSNASAL/Sean Read/Elderly flow paper/images/slicedata/PA.py", line 24, in clip DataRepresentation1 = GetDisplayProperties( FluentCaseReader1 ) NameError: global name 'GetDisplayProperties' is not defined Code:
>>> pv.Clip(so) <paraview.servermanager.Clip object at 0x7f8fd451dd50> |
|
October 19, 2015, 10:51 |
|
#6 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
In the beginning of your script files you should import the ParaView Simple module. Simple module contains all the filters (Clip, Slice...). Either by
Code:
from paraview.simple import * Clip(..) Code:
import paraview.simple as pv pv.Clip(...) |
|
October 19, 2015, 23:04 |
|
#7 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
seems to have done the trick, thanks again!
|
|
December 9, 2015, 20:11 |
|
#8 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
hey you know this is weird, but I just did a clean install of paraview4.4 with openfoam from the debian package on ubuntu 15.10 and the same original problem with importing functions from the local folder has manifested. Do you have any thoughts as to why this might be?
Last edited by seanread; December 9, 2015 at 22:15. |
|
Tags |
pvpython |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to write k and epsilon before the abnormal end | xiuying | OpenFOAM Running, Solving & CFD | 8 | August 27, 2013 16:33 |
pisoFoam with k-epsilon turb blows up - Some questions | Heroic | OpenFOAM Running, Solving & CFD | 26 | December 17, 2012 04:34 |
Upgraded from Karmic Koala 9.10 to Lucid Lynx10.04.3 | bookie56 | OpenFOAM Installation | 8 | August 13, 2011 05:03 |
IcoFoam parallel woes | msrinath80 | OpenFOAM Running, Solving & CFD | 9 | July 22, 2007 03:58 |
Could anybody help me see this error and give help | liugx212 | OpenFOAM Running, Solving & CFD | 3 | January 4, 2006 19:07 |