HScript, need some help

   10829   5   1
User Avatar
Member
344 posts
Joined: July 2005
Offline
I don't know anything about Python, Tcl/Tk, or scripting in a Linux Shell, as such, I'm having a hard time muddling through the documentation for scripting in Houdini. What I want to know is if it's possible to extract information from Houdini Apprentice on my model, it's UVs, and basic animation information into a text file. I wanted to try bringing models and animation from houdini into a DirectX viewer I'm working on. If anyone can give me some pointers in the right direction, or maybe a simple example of pulling the vertex coordinates of a cube out into a text file I'd be most appreciative.
User Avatar
Member
1631 posts
Joined: July 2005
Offline
Hi Michael,

You can type 'help' or 'exhelp' in the textport to get a list of all hscript commands. From the list, you can then type ‘help command’ to get more instructions. For example:

/ -> help chwrite
Usage: chwrite channel_pattern … filename

This command will write out the specified channels as columns
of raw values with one sample per frame across the given frame
range. If no range is given the current global animation time
range will be used. Channels will be output in columns in the
order specified. The output will be saved as ascii data unless
the file has a suffix of “.bchan”, in which case binary format
will be used.

Note that channels need not be raw in order to save them using
chwrite. The channel values will be sampled at the current frame
rate.

Also note that the order of channels resulting from a pattern
match is not well defined.

See also: chread chadd chkey chls
or

/ -> exhelp primuv
float primuv (string SOP, float prim_num, string attrib_name, float attrib_index, float u, float v)
Evaluates the specified attribute at a parametric (u,v) position on the
primitive. u and v are unit values, defined in the interval. When given
the “P” or “Pw” attribute, the x, y, or z image of the (u,v) domain point will
be returned. If the primitive is a face type or a circle, v is ignored.

Note: if the primitive is a polygon or a mesh, u and v are defined in terms of
the number of vertices, or rows or columns respectively. Currently, only the
positional attribute of quadric primitives can be evaluated.

For example:
primuv(“/obj/geo1/tube1”, 0, “Cd”, 1, 0.7, 0.3)
Will evaluate the Green component of the diffuse color attribute at a location
on primitive 0 given by the parametric coordinates (0.7,0.3).

See also: primduv, normal, curvature, unituv
If you have a keyword, eg, “vertex”, you can use either 'help -k vertex' or 'exhelp -k vertex' to get a list of commands that contains “vertex” in the the instructions.

For the vertex coordinates of a box, have you tried saving a Box SOP as a .geo file? Put down a Box SOP, Right-Click-Hold on the SOP & select “Save Geometry…”.

In the pop-up dialog box, choose where you want to save the file to using the ‘+’ button then click Accept. Back in the dialog box, please click on the fly-out arrow ( ‘>’ button ) & select '.geo' from the list. Finally, click Accept to save out the file.

You can then use your favourite text editor to view the .geo file which contains the vertex coordinates you're looking for.

For writing out animation channels, you can use ‘chwrite’ from the example above or you can use CHOPs.

I hope the above helps!

Cheers!
steven
User Avatar
Member
344 posts
Joined: July 2005
Offline
This has helped alot. Much easier than digging through the help files. I'm still stuck on one point though. The tip on geo files was good but they give me way too much info. It seems to be possible to write recursive functions in HScript to dig out only the info I need, but I cant seem to figure out how one would going about formatting the text and sticking it in a file. I guess what I'm loking for is something equivalent to “printf” in C and a way to save the results of my printf to an ascii file.

I've been using help and exhelp -k print or -k file and haven't turned up anything that looks like what I need. Any ideas?
User Avatar
Member
7710 posts
Joined: July 2005
Online
Hi Michael,

Try “exhelp print”. Note that I just noticed a typo in the example. It should be “print” and not “printf”. “help exread” is also something useful if you're going to write expression functions.

Just a suggestion but exporting data via CHOPs might be an easier way to do things than writing scripts. You will find that the Geometry CHOP allows you to pull only the information you want from SOPs. After that, right-click on the tile and choose to “Save Data Channels…” Just make sure you name the file as a .clip (for ASCII) as opposed to .bclip (for binary).

If you want to export geometry, I really do think that saving them out in some specific format is the best way to go. The .geo format is pretty easy to parse. And if you don't like that, you can always find some free code to import one of the popular formats like .OBJ and write those out from Houdini instead of .GEO files.
User Avatar
Member
344 posts
Joined: July 2005
Offline
Thanks so much. These two posts have been very helpful. The thing is I didn't want to parse ascii files in the viewer. I've got a basic binary format of my own making, and my plan was to write a tool to parse the ascii file and save them as binary for the viewer. I wanted to create a really generic ascii file formatted a certain way so I could easily use the tool with ascii files I output from Maya or Houdini. Thanks for the help you've given me. This isn't going to be as easy as I had hoped, but at least it looks like it's possible.

Just out of curiosity, it's my understanding that the HDK doesn't work with Apprentice, you need a license for the HDK tools, does the HDK license cost anything extra when you buy Master, Select, or Escape, and if so how much is it?
User Avatar
Member
7710 posts
Joined: July 2005
Online
Hi Michael,

Rather than quote something here, check out the pricing info available in the main Houdini website under Sales. (See Sales link above).

Currenty, here's the direct link to it:
http://www.sidefx.com/sales/pricing/index.html [sidefx.com]

Cheers,
-Edward
  • Quick Links