TCL 脚本:变量作为函数的参数 [英] TCL script: variable as argument of a function
问题描述
我正在尝试使用 Amira 编写一些简单的脚本,它使用 TCL,但我不能保证它是标准版本.我想从一个对象中读取一个属性并将其分配给另一个对象.
I am trying some simple scripting with Amira, which uses TCL but I cannot assure that it's the standard version. I want to read a property from an object and assign it to another object.
在命令窗口中,过程如下:
In the command window the procedure would be the following:
Image1 getTransform
Image1 getTransform
0.1 0.2 0.3 0 0 0 0 0 0 1
0.1 0.2 0.3 0 0 0 0 0 0 1
Image2 setTransform 0.1 0.2 0.3 0 0 0 0 0 0 1
Image2 setTransform 0.1 0.2 0.3 0 0 0 0 0 0 1
我想在不手动复制粘贴 getTransform 的结果的情况下做同样的事情
I want to do the same without manually copy pasting the result of getTransform
以下不起作用(也就是说 setTransform 不带参数执行)
The following do not work (taht is to say setTransform is executed without arguments)
Image2 setTransform [Image1 getTransform]
或
set myT=Image1 getTransform
Image2 setTransform $myT
我确定我只需要适当地使用 $ [ { ,但到目前为止我所尝试的还没有给出任何结果
I am sure I just need to appropriately use $ [ { , but what I've tried so far has not given any result
推荐答案
如果您使用的是 Tcl 8.5 或更新版本,请使用 {*}
参数扩展:
If you are using Tcl 8.5 or newer, then use the {*}
argument expansion:
Image2 setTransform {*}[Image1 getTransform]
这正是您想要的.
如果您使用的是旧版本的 Tcl,那么您必须使用 eval
,这是一个非常有用的命令,如果使用不当,很多事情都会出错:
If you are using an older version of Tcl, then you have to use eval
, a very useful command, where many things can go wrong if not used correctly:
eval [linsert [Image1 getTransform] 0 Image2 setTransform]
linsert
在这里用于构建一个propper 列表以避免双重替换(这几乎总是不好的).
The linsert
is used here to build up a propper list to avoid double substitution (which is almost always bad).
这篇关于TCL 脚本:变量作为函数的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!