[Paraview] Python scripting of selection / labels on contours

Deij, Menno M.Deij at marin.nl
Tue Feb 28 07:54:06 EST 2012


Of course, hours after this second message I solved it! So for future reference, this is my approach:

After slicing through the contour lines, label the points as follows:

slice = Slice(Input=myContourLines, SliceType='Plane')
slice.SliceType.Origin=[0,0,0]
slice.SliceType.Normal=[0,0,1]
di = slice.GetDataInformation()
nPoints = di.GetNumberOfPoints()

# vital missing piece of information follows: create a selection source 
selectSource = IDSelectionSource()

# populate it with the IDs of the points to be selected
# this is a list that is [0L,0L,0L,1L,0L,2L,...,0L,nL]
IDs = []
for i range(nPoints):
    IDs.append(0L)
    IDs.append(long(i))

# set the IDs and set the selection input
selectSource.IDs = IDs
slice.SetSelectionInput(0,selectSource,0)

# render the image & modify the label visibility and formatting
rep = Show()
rep.SelectionPointLabelVisibility = 1
rep.SelectionPointFieldDataArrayName = 'Pressure'
rep.SelectionPointLabelFormat = '%3.2f'
rep.SelectionPointSize = 0
rep.SelectionPointLabelColor = [0,0,0]


Kudos to Utkarsh, whose post from 2010 showed the use of a SelectionSource and put me on the right track.

Gr.
Menno


-----Original Message-----
From: paraview-bounces at paraview.org [mailto:paraview-bounces at paraview.org] On Behalf Of Deij, Menno
Sent: Tuesday, February 28, 2012 11:39 AM
To: paraview at paraview.org
Subject: Re: [Paraview] Python scripting of selection / labels on contours

Anyone have any ideas on making selections from Python script in ParaView? Or how to put labels with values on contours? 

Thanks and best wishes,


Menno Deij



-----Original Message-----
From: paraview-bounces at paraview.org [mailto:paraview-bounces at paraview.org] On Behalf Of Deij, Menno
Sent: Friday, February 17, 2012 1:35 PM
To: paraview at paraview.org
Subject: [Paraview] Python scripting of selection / labels on contours

Dear all,

What I'm trying to achieve is to get labels on contourlines from a python script (that is, non-interactively). To get started, I followed the following advice given on the list on Sep 13, 2010:

"Try doing a slice through all the contour lines, and then selecting the points on the slice that you want to label. Then turn on the selection inspector and show point labels with the variable you want to plot. I've found the number of trailing zeros is a bit annoying, as there's no control over the number format, and I normally choose integer values for the contours. The selection labels aren't persistent so a state file will lose these labels, and you'll have to reselect them if you need another plot."

This works very well in interactive mode when the user makes the selection using the selection tool.

Now, what I want to achieve is to do this from a Python script. I have not been able to reproduce the result if I follow or interpret the output from Python trace when I perform the actions described.

So: if you have any ideas on 1) to achieve selections from python script and/or 2) to create labels on contourlines from python script, I'd be very much obliged.

All the best,


Menno


dr. ir. Menno A. Deij
Software Engineer
Maritime Simulation Group
E mailto:M.Deij at marin.nl
T +31 317 49 35 06

MARIN
2, Haagsteeg, P.O. Box 28, 6700 AA Wageningen, The Netherlands
T +31 317 49 39 11, F , I www.marin.nl

_______________________________________________
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