tcl inside Houdini

   4913   6   1
User Avatar
Member
201 posts
Joined: July 2005
Offline
Okay, tcl problem …

I want to be able to use Houdini variables from inside a tcl file, do something with the values then create a new Houdini variable.

Suppose I have a Houdini variable called foo (set foo = 100).

I have a tcl file that looks something like:
set tmpA
hscript set fum=$tmpA
exit 0

I should get a new variable inside Houdini called fum which is equal to 100, right?! But I don't.

If I manually do these commands, here's what I get:

% set tmpA
{100}

% hscript set fum=$foo
Invalid variable name ({fum)
Unknown command: }



I have no idea what is going on. On top of this, it seems I can't even pass arguments to the command line. If I try something like this in Houdini textport “tcl foo.tcl 123” & I'm asking it to report back the $argv1 (which is a valid tcl variable) it complains that argv1 isn't valid.

Help!
Cheers,
Rob
Digital Supervisor | Stargate Studios Toronto
User Avatar
Member
7734 posts
Joined: July 2005
Offline
It works for me. Why are you adding the braces?

(from houdini textport)
/ -> tcl
(in tcl)
% set foo 3
% hscript set fum = $foo
(quit tcl/tk)
(in houdini textport)
/ -> echo $fum
3

As for your args problem, I think you're confusingthe syntax between hscript and tcl. In tcl, the command line arguments are put into the list variable $argv. Thus to access the first argument, you need to use something like:
User Avatar
Member
201 posts
Joined: July 2005
Offline
edward
It works for me. Why are you adding the braces?

(from houdini textport)
/ -> tcl
(in tcl)
% set foo 3
% hscript set fum = $foo
(quit tcl/tk)
(in houdini textport)
/ -> echo $fum
3

Yep, this works if I set variable inside tcl and pass it to Houdini. However, my case is slightly different …

Try this. Set a variable in Houdini first (set foo = 123). Now, go into tcl. At this point, I want tcl to grab the value stored in Houdini variable foo. The way to do this is via the special hscript command embedded in tcl. In this case, I want to set a tcl variable so I do:

set myTclVar

The reason to use braces is to prevent tcl from expanding $foo - I want to pass the variable to hscript. Ideally, the tcl variable myTclVar should be equal to 123. Suppose I do something to myTclVar and create a new variable myNewVar equal to 456. Now, I want to set a new Houdini variable fum to be equal to myNewVar. Thus:

hscript set fum = $myNewVar

Unfortunately, none of this works (refer to my first post).


As for your args problem, I think you're confusingthe syntax between hscript and tcl. In tcl, the command line arguments are put into the list variable $argv. Thus to access the first argument, you need to use something like:

Doh … I forgot. Should've read the manual closer. Thanks for clearing that up.

Cheers,
Rob
Cheers,
Rob
Digital Supervisor | Stargate Studios Toronto
User Avatar
Member
7734 posts
Joined: July 2005
Offline
Ok, back to the original post. The curly braces prevent expansion but then it's also passed to hscript so that's why it's not working.
User Avatar
Member
201 posts
Joined: July 2005
Offline
edward
Ok, back to the original post. The curly braces prevent expansion but then it's also passed to hscript so that's why it's not working.

Yep, you're right. So, does this mean tcl cannot get at Houdini variables? Anyone at SESI want to comment?

Because of this roadblock, I decided to pass arguments to tcl (thanks to Edward for pointing out the correct method). The call to the tcl file is being done thru a cmd file.

myCmdFile.cmd
set -p origVar = 10
tcl //directory/test.tcl $origVar


test.tcl
set tmpVar
hscript set -p newVar=$tmpVar
exit 0


Please note the usage of the set command. I had to use the ‘-p’ option in order to create the Houdini variables. If you don't do this, the variable isn't created (seems -g also works).

Cheers,
Rob
Cheers,
Rob
Digital Supervisor | Stargate Studios Toronto
User Avatar
Staff
269 posts
Joined: July 2005
Offline
The error you were getting should be fixed in the latest version of Houdini 8.
User Avatar
Member
201 posts
Joined: July 2005
Offline
lucas
The error you were getting should be fixed in the latest version of Houdini 8.

Yep, it's fixed in version 8.0.313. Thanks!
Cheers,
Rob
Digital Supervisor | Stargate Studios Toronto
  • Quick Links