[vtkusers] Re: simple question about Tcl and VTK

Goodwin Lawlor goodwin.lawlor at ucd.ie
Tue Oct 10 18:29:32 EDT 2006


Romy Schneider wrote:
> I know there is probably some simple fix for this or some Tcl syntax I 
> am just not aware of, but I seem to be having issues combing commands 
> when arrays of numbers are involved.  For instance, the following code:
> 
> vtkCamera cam1
> cam1 SetFocalPoint 0.0 0.0 0.0
> vtkLight light
> light SetFocalPoint [cam1 GetFocalPoint]
> 
> returns the following error:
> 
> "
> Error in startup script: Object named: light, could not find requested 
> method: SetFocalPoint
> or the method was called with incorrect arguments.
> 
>     while executing
> "light SetFocalPoint [cam1 GetFocalPoint]"
> "
> 
> This is inside a script that I run with % vtk script.  If I change the 
> fourth line to "light SetFocalPoint 0.0 0.0 0.0", it works.  I am very 
> confused why I am getting an error, there are plenty of VTK/Tcl examples 
> in the literature that use these very commands.  It seems to happen 
> whenever the command in [ ] returns an array or list of numbers.  Is 
> there some setting or something in Tcl that I am missing? 
> 
> thanks,
> Romy

Hi Romy,

You're getting an error  because [cam1 GetFocalPoint] returns a list 
containing the 3 coords of the focal point. "light SetFocalPoint" see 
this as one argument (ie a list of 3 values) but it expects 3 arguments 
- the x, y, z coords.

There are a couple of ways to deal with this:

1. Use the "eval" commmand, to expand the result of [cam1 
GetFocalPoint], (eg)

eval light SetFocalPoint [cam1 GetFocalPoint]

2. Use [scan] or [lindex] to set new vars x,y and z and pass these to 
the command, (eg)

scan [cam1 GetFocalPoint] "%f %f %f" x y z
light SetFocalPoint $x $y $z

3. If you're using Tcl8.5, there's new syntax: {expand} (eg)

light SetFocalPoint {expand}[cam1 GetFocalPoint]


Maybe, VTK C++ methods that expect a pointer to an array should be 
wrapped by a tcl command that expects a list...


hth

Goodwin




More information about the vtkusers mailing list