CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [General] Slice origin as annotation in animation (https://www.cfd-online.com/Forums/paraview/121051-slice-origin-annotation-animation.html)

bozack July 20, 2013 04:47

Slice origin as annotation in animation
 
I am making an animation where I vary the origin of a slice through my gaussian cube data, and would like to have an annotation of what value the X-coordinate of the slice origin is, for each frame.

I have tried using the Python Annotation Filter, but I simply cannot figure out how to get to the slice origin value.

My first guess was something like
Code:

"Slice origin in X = %f" % (XSlicesOrigin[0])
but this does not work at all. How should I do it?:confused:

wyldckat July 21, 2013 12:07

Greetings Pia and welcome to the forum!

How exactly are you varying the slice? Because it might be possible to generate the annotation directly in the code where you're doing the slice movement.

Best regards,
Bruno

bozack July 21, 2013 17:38

Quote:

Originally Posted by wyldckat (Post 441051)
How exactly are you varying the slice? Because it might be possible to generate the annotation directly in the code where you're doing the slice.

I'm working in the ParaView GUI (I didn't know that you could get to the code behind that?). I use the animation view and simply choose the slice in the dropdown menu, and afterwards the origin value, and interpolate its value along with the time in the animation.

bozack August 12, 2013 05:44

bump
 
I'm just bumping this thread again, in the hope that someone can help me?

wyldckat August 16, 2013 18:10

Hi Pia,

Sorry, but I've been busy for the past few weeks and didn't manage to look into this until now.

And I've been playing around with ParaView 3.98.0 for the past 2 hours or so and the only solution I could manage to figure out was as follows:
  1. Prepare your post-processing case on ParaView 3.98.0 or newer, including an instance of the "Slice" filter and of the "Python Annotation" filter.
  2. Place the following code inside a python script file, e.g. "syncAnnotation.py":
    Code:

    try: paraview.simple
    except: from paraview.simple import *
    paraview.simple._DisableFirstRenderCameraReset()

    Slice1 = FindSource("Slice1")
    PythonAnnotation1 = FindSource("PythonAnnotation1")
    PythonAnnotation1.Expression = "'Slice origin in X = %f' % " + str(Slice1.SliceOffsetValues[0])

    Render()

    Adjust the names "Slice1" and "PythonAnnotation1" accordingly to your existing session. And also adapt the code for "PythonAnnotation1.Expression" to your liking; since it's based on your first post, it should be easy for you to understand what the code does.
  3. On the menu, click on "Macros -> Add New Macro" and select the file "syncAnnotation.py".
  4. You should now have this macro on the menu "Macros", as well as a button named "synAnnotation" on the Macros toolbar (on/off in the menu "View -> Toolbars -> Macros Toolbars").
  5. Now, whenever you change the time instance, use this macro and it will update the python annotation accordingly.
Here are some of the references I used:
What I've tried:
  1. Tried using a "programmable source" to run the contents of this script, but for some reason it won't reach the currently open session.
  2. Tried to use in the expression of the "Python Annotation" filter to use the following code:
    Code:

    paraview.servermanager.ProxyManager().GetProxy("sources", "Slice1").SliceOffsetValues[0]
    It's the absolute path to the following command:
    Code:

    FindSource("Slice1").SliceOffsetValues[0]
    But the first one fails for the same issue with not being able to connect to the session; and the second fails due to not having access to "paraview.simple" from these programmable filters and sources.
  3. Tried to write an XML proxy plugin, either source or filter, but the more I read the XML files, the more it looked like it would not work, due to how the proxies work. Perhaps I missed something, so here are the references for this idea:
  4. Due to the non-accessible session, I also tried to use a "programmable source" to open a new session, but the problem is that it would require a new session each time it changed the time snapshot... the code I had used was:
    Code:

    from paraview import servermanager

    servermanager.Connect('localhost',11111)
    servermanager.ProxyManager().GetProxy("sources", "Slice1").SliceOffsetValues[0]

    Although this required pvserver to have been executed first on another terminal. But this failed because only one session may be connected to a server, which leads to a crash the second time it tries to connect.
  5. Tried to use "--multi-clients" with pvserver, but it would lock up ParaView when I used the code from the attempt #4.


Best regards,
Bruno

akidess January 10, 2017 10:29

If you want to modify the origin instead of the offset the code is:

Code:

try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

Slice1 = FindSource("Slice1")
PythonAnnotation1 = FindSource("PythonAnnotation1")
PythonAnnotation1.Expression = "'Slice origin in X = %f' % " + str(Slice1.SliceType.Origin[0])

Render()


ch_jaehnel July 27, 2018 04:37

I know this thread is quit old, but maybe one of you could help me. I initialised this macro, it all worked fine.



But is there a possibility to syncronise the macro while exporting an animation? Yet I would need to click on the macro for every new timestep, which should go automaticly by skipping the timestep.


Thank you for your help!


All times are GMT -4. The time now is 05:07.