beginners HScript question

   5932   9   2
User Avatar
Member
5 posts
Joined: Sept. 2006
Offline
I have what i guess is a real beginners question reg. HScript. I'm moving from max and maxscript (which is javascript inspired syntax) to Houdini and I have absolutely no experince with shell scripts and the like. I want to make a simple script that generates 10 boxes af offsets them 10 units each.
The script looks like this:

opcf /obj
opadd geo
opcf geo1
oprm file1
for i=1 to 10
opadd box
opadd xform
opwire box$i xform$i
set offset=$i*10
set g=$offset 10 10
opparm xform$i t ( $g )
end

The problem is that my g variable is not (as I would like it to be):
(10 10 10)
(20 10 10)
(30 10 10)
etc.. but instead:
(10*1 10 10)
(10*2 10 10)
(10*3 10 10)
which is not valid. How do I get HScript to actually evaluate the statement instead of just treating it as a string? I tried set offset=eval($i*10) but thats no good either. I have a strong feeling that i'm missing something very basic here..?
User Avatar
Member
12471 posts
Joined: July 2005
Offline
Your problem here is that you have to evaluate the math (using backticks):

set offset=$i*10

…should be…

set offset=`$i*10`

…otherwise it'll treat it as a string. Remember that hscript (like shell script) is not “strongly typed” and therefore has no idea that you want your variable offset to be numeric rather than a string.

It may interest you to know that it's been confirmed that Houdini 9 will have full support for Python implemented as what they call HOM. http://forums.odforce.net/index.php?showtopic=4609 [forums.odforce.net]

Hope this helps,
Jason
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
User Avatar
Member
5 posts
Joined: Sept. 2006
Offline
Thanks a lot - that was very quick and helpful.
User Avatar
Member
7722 posts
Joined: July 2005
Offline
I assume though that you didn't want to script this because you have to. It's only 2 SOPs to do get the same geometry result.
User Avatar
Member
5 posts
Joined: Sept. 2006
Offline
well actually, since you ask, I could use a little advice regarding that . I know I can just make a box and add a copy node, but I need to use the boxes in a dynamics simulation. When adding a Geometry copy in my dop network, I can only acces the copied boxes as one object. Is there a way to extract the individual objects from a copy somehow, for use, for instance, in a dynamics simulation? Or how would you go about this otherwise?
User Avatar
Member
387 posts
Joined: July 2005
Offline
Ed is right. Eschew scripting…

Use a box sop, and a copy sop. Set it to make 3 copies, say. Then append a CONNECTIVITY SOP, change Connectivity Type to Primative. Then append a PARTITION SOP and set the rule to “pr_$CLASS”. Now, MMB on the Partition Sop and you should see you have 3 groups: pr_0, pr_1, and pr_2. You can use these groups in your Dop's (eg. Fractured Object DOP)

The cool thing about doing it in sops (copy sop) is you can change the number of copies at any time, and the number of groups will update accordingly. Very flexible. Much better than being stuck with the junk created from a script.

cheers,
ben.
''You're always doing this: reducing it to science. Why can't it be real?'' – Jackie Tyler
User Avatar
Member
5 posts
Joined: Sept. 2006
Offline
Hi Ben

Thanks a lot for this.. This also made it dawn on me that instead of using a gazillion RBDObjects and merge them all, I can use the RBDfraturedobject and groups of objects.. This also made by RBD simulation substantially faster, which was badly needed.
User Avatar
Member
557 posts
Joined: July 2005
Offline
If you are doing something as simple as copying boxes (or other geometry) and tossing them into an RBD Fractured Object, then you don't even need the Connectivity and Partition SOP trick.

Instead, just turn on the toggle at the bottom of the Copy SOP, that says “Create Output Groups”

Then the field “Copy Groups” will become active, and you'll notice that the default in there is “copyGroup$CY” If you middle mouse on the Copy SOP at this point, you'll see one group per copy, called
copyGroup0
copyGroup1
copyGroup2
etc

So you can change this string to whatever you want, and get those groups directly into DOPs as objects.
User Avatar
Member
557 posts
Joined: July 2005
Offline
Oh, and one other thing - if you do the copy by connecting the Copy SOP to a set of template points (second input), then the output groups variable should be changed to $PT. In other words, change it to
copyGroup$PT
to get a set of uniquely named groups.
User Avatar
Member
5 posts
Joined: Sept. 2006
Offline
Thanks craig - however i have 3 copy nodes (one for each axis, making a 3D box grid), and finally the connectivity and fraction nodes, so I guess I can't use the copy to groups function in this case. I could of course use a subdivided box as distrubtion object instead of the three copy nodes i guess, and the copy to groups.
  • Quick Links