[Paraview] Insert text source into view in a script

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Wed Jul 15 16:27:18 EDT 2009


Oops correction, I had a typo in the script:
#=======================
from paraview.simple import *
Sphere()
Show()
Render()

t = Text()
t.Text = "Hello World"
Show()
Render()
#=======================



On Wed, Jul 15, 2009 at 4:25 PM, Utkarsh
Ayachit<utkarsh.ayachit at kitware.com> wrote:
> Does the following script work:
> #=======================
> from paraview.simple import *
> Sphere()
> Show()
> Render()
>
> t = Text()
> t.Text = "Hello World"
> t.Show()
> Render()
> #=======================
>
> Utkarsh
>
>
> On Wed, Jul 15, 2009 at 4:23 PM, M. Nawijn<nawijn at gmail.com> wrote:
>> Hello Utkarsh,
>>
>> Thank you for the fast response. I tried this already before posting
>> my question to the mailing list, however, when I inserted the Show(),
>> I get the following error:
>>
>> vtkFileSeriesReader : [ ...........]
>> vtkPainterPolyDataMapper : [ ...........]
>> vtkPainterPolyDataMapper : [ ...........]
>> Traceback (most recent call last):
>>  File "test3.py", line 39, in <module>
>>    Show()
>>  File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
>> line 112, in Show
>>    rep = GetDisplayProperties(proxy, view)
>>  File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
>> line 101, in GetDisplayProperties
>>    return GetRepresentation(proxy, view)
>>  File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/simple.py",
>> line 90, in GetRepresentation
>>    rep = servermanager.GetRepresentation(proxy, view)
>>  File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/servermanager.py",
>> line 1989, in GetRepresentation
>>    if rep.Input == aProxy:
>>  File "/home/nawijn/scratch/paraview-bin/Utilities/VTKPythonWrapping/paraview/servermanager.py",
>> line 357, in __getattr__
>>    return getattr(self.SMProxy, name)
>> AttributeError: Input
>>
>>
>> Any suggestions?
>>
>> On Wed, Jul 15, 2009 at 10:17 PM, Utkarsh
>> Ayachit<utkarsh.ayachit at kitware.com> wrote:
>>> "Text" is a data source similar to the reader. You need to  "Show" it
>>> to add it to the active view.
>>>
>>> Just do:
>>> load = 100.0
>>> # Don't know how to get this into the view
>>> text = Text()
>>> text.Text = "Load %6.3f" % load
>>> Show()
>>>
>>> Utkarsh
>>>
>>> On Wed, Jul 15, 2009 at 4:01 PM, M. Nawijn<nawijn at gmail.com> wrote:
>>>> Hello,
>>>>
>>>> I am a newbie in Paraview Python scripting, so I apologize upfront if
>>>> this is a trivial question.
>>>>
>>>> I am processing a set of datafiles obtained from an optical
>>>> measurement system. I so far succeeded in loading the data file,
>>>> adding a color legend and storing the resulting view in a image file.
>>>> Sample code is posted below.
>>>>
>>>> What I would like to do next is add a text source to the view to
>>>> provide some contextual information about the data (in particular the
>>>> external load level at which the data was captured). I managed to add
>>>> a text source to an "empty" view (so without first reading the data),
>>>> but I cannot find a way to have the data and text source together.
>>>>
>>>> Can someone explain how I can add this to the view?
>>>>
>>>> Kind regards,
>>>>
>>>> Marco
>>>>
>>>> #==== What I have so far ===================================================
>>>>
>>>> from paraview.simple import *
>>>>
>>>> lt = MakeBlueToRedLT(-1.0, 1.0)
>>>>
>>>> bar = servermanager.rendering.ScalarBarWidgetRepresentation()
>>>> bar.LookupTable = lt
>>>> bar.LabelColor = [0.0, 1.0, 0.0]
>>>> bar.Title      = r'W [mm]'
>>>> bar.TitleColor = [0.0, 1.0, 0.0]
>>>> bar.LabelFontSize = 14
>>>> bar.AspectRatio   = 15.0
>>>> bar.AutomaticLabelFormat = 0
>>>>
>>>> reader = XMLUnstructuredGridReader(FileName='disp-stage-%d.vtu' % 17)
>>>>
>>>> Show()
>>>>
>>>> #UpdatePipeline()
>>>>
>>>> view = GetActiveView()
>>>> view.Background = [0,0,0]
>>>> ResetCamera(view)
>>>> view.UseOffscreenRenderingForScreenshots = 0
>>>>
>>>> dp = GetDisplayProperties()
>>>> dp.ColorArrayName = 'W'
>>>>
>>>> rep = GetRepresentation()
>>>> rep.LookupTable = lt
>>>>
>>>> view.Representations.append(bar)
>>>>
>>>> load = 100.0
>>>> # Don't know how to get this into the view
>>>> text = Text()
>>>> text.Text = "Load %6.3f" % load
>>>>
>>>> # Image does not show the text
>>>> WriteImage('test.png')
>>>> _______________________________________________
>>>> 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