VEX debugging methods

   2925   6   1
User Avatar
Member
313 posts
Joined: Oct. 2016
Offline
Hi,

is there a way to dump arbitrary data types of data somewhere?

With Python it is so easy to convert anything to strings and simply print it out. With VEX it is not the same. When something is wrong the code simply breaks.

printf(string(my_int)); // does not work
warning(string(my_int)); // does neither work

How do you do this or something equivalent?

Or is there some good debugging tool to use?

Some other threads on the same topic are here:
printf with only one print [www.sidefx.com]
copy a variable to a temp attribute; use the built-in visualizer for normals; bind export [www.sidefx.com]
printVOP; Display a temp attribute in the details view [www.sidefx.com]
printf; Print VOP [www.sidefx.com]

Comments about previously found related threads:
In geometry (SOPS) there is no print operator/node, is there?
What is the "details view", is it the same as the "Node info" window?

However, I'm used to dealing with various data types and simply being able to quickly convert and print them all out. How do you deal with that for any data type? Say you have arrays, dictionaries, integers, floats, strings and whatnot?

In essence I just want to be able to validate my intermediate inputs and outputs before proceeding.
Edited by SWest - Jan. 27, 2023 17:02:56
Interested in character concepts, modeling, rigging, and animation. Related tool dev with Py and VEX.
User Avatar
Member
51 posts
Joined: June 2020
Offline
you can use printf("My attribute = %d",@attribute) or printf("My myVariable= %d",myVariable)
Edited by uakin - Jan. 27, 2023 16:59:49
User Avatar
Member
9416 posts
Joined: July 2007
Offline
you can also use %g for generic type that works with arrays or ducts

A lot of this is described in a help page
https://www.sidefx.com/docs/houdini/vex/functions/printf.html [www.sidefx.com]
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
313 posts
Joined: Oct. 2016
Offline
Thanks uakin and tamte for quick replies.

The first user case with a point neighbours array works.

It looks like this:

printf("pt id from array = %d ",pt);

Now I see the point ids. Great!
Interested in character concepts, modeling, rigging, and animation. Related tool dev with Py and VEX.
User Avatar
Member
9416 posts
Joined: July 2007
Offline
a lot of times can be helpful to output data as attributes at different stages of wrangle
then you can observe them in geometry spreadsheet
especially useful for arrays and dict attribs
or also matrices as spreadsheet can nicely display them decomposed into SRT at no extra effort

I usually use print only for variables that are being overriden during runtime, like within for loop etc
Edited by tamte - Jan. 27, 2023 17:29:45
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
313 posts
Joined: Oct. 2016
Offline
Thanks again. While considering and testing the above two suggested methods (geometry attributes and printf) I started looking into a quick method to get the shell output into Houdini. On Linux the menu option "Windows > Shell" does not work.

Here's a quick work around for now. With this I get the output into the Python shell Window that I usually keep open. This could be improved with parsing, but for now it is simply a dump of the text.

from datetime import datetime


def parseNohup():
    '''Read and parse the output from nohup.out. 
    Primary purpose is vEX debugging.
    Dependencies: Linux. set user in path_to_file. from datetime import datetime
    Houdini is launched with nohup like this "nohup [...] &".
    This sends the output to /home/[user]/nohup.out.
    Then this output can be parsed.
    This code could, for example, be stored in a shelf button'''

    
    # code for reading and printing the file
    path_to_file = "/home/[user]/nohup.out"
    with open(path_to_file) as f:
        print(f.read())


    # code for emptying the file after reading
    message = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
    with open(path_to_file, 'w') as f:
        f.write(message)


parseNohup()
Edited by SWest - Jan. 28, 2023 12:45:23
Interested in character concepts, modeling, rigging, and animation. Related tool dev with Py and VEX.
User Avatar
Member
54 posts
Joined: June 2017
Offline
I wanted to second the approach of outputting values as attributes. I've crashed Houdini by trying to print out results to console many times, so I find it to be safer and it works quite well.
Houdini TD, I focus on tools for procedural asset creation.

www.jaworenko.design
  • Quick Links