Just returning to Houdini after a long hiatus and the widespread use of python is pretty new to me. I understand that in a production pipeline python can be used to great effect but I'm wondering if it's worth the learning effort for a small (i.e. one man... aka me) studio like mine.
For example, I've figured out that the HScript call for a bounding box (i.e. bbox("../box1", D_YMAX)) is hou.node("../box1/").geometry().boundingBox().sizevec() in python.
What advantage is python for use like this primarily as expressions in nodes? To me, there is far greater complexity and risk of error over HScript (assuming most usage is simple like this)? Is HScript being completely deprecated?
I'm obviously missing and/or misunderstanding something. Essentially, I'm asking what is the real-world use of python and do I need to learn it?
Kind thanks,
Lonny
Python vs HScript - use case
3279 9 2- muttoab
- Member
- 10 posts
- Joined: July 2005
- Offline
- jsmack
- Member
- 8043 posts
- Joined: Sept. 2011
- Offline
Different users have different preferences, but I try to only use Python where it makes sense. Such as when code needs good reusability, has complex logic, processes strings, reads external files, or requires an external python library. Python is useful for control and automation, such as building shelf tools or sequencing operations.
Personally, I would never use python for the example you give, Hscript is just easier and more concise. I rarely use python for directly working with geometric values in expressions, but that doesn't mean you should never use it. I tend to rarely use HScript for that anymore either. VEX is the language of choice for geometry manipulation.
If I needed to pull a values from a database and build a menu on a node, I definitely would use Python.
The emerging world of USD in Solaris is an area where Python is often the most applicable. Hscript has very little coverage in this area, and VEX only has so much utility.
Personally, I would never use python for the example you give, Hscript is just easier and more concise. I rarely use python for directly working with geometric values in expressions, but that doesn't mean you should never use it. I tend to rarely use HScript for that anymore either. VEX is the language of choice for geometry manipulation.
If I needed to pull a values from a database and build a menu on a node, I definitely would use Python.
The emerging world of USD in Solaris is an area where Python is often the most applicable. Hscript has very little coverage in this area, and VEX only has so much utility.
- Soothsayer
- Member
- 874 posts
- Joined: Oct. 2008
- Offline
There's no point for most python one-liners used as parameter expressions. There's the odd case where you need something that is not available in hscript but I don't encounter it very often and if I do it is freaky. The most common legit use of such python one-liners is perhaps anything to do with .pressButton()
For a one-man studio where pipeline isn't such an issue Python can be useful when you need to manipulate strings. That's a real pain in vex, nodes, or hscript but often super neat in Python. Another common case would be anything to do with arrays that isn't too speed critical. With list comprehensions and other functional programming tools it's often very easy to search, rearrange and manipulate lists of things. Or if you want to venture into more esoteric areas like machine learning then Python makes that relatively easy to play around with.
For a one-man studio where pipeline isn't such an issue Python can be useful when you need to manipulate strings. That's a real pain in vex, nodes, or hscript but often super neat in Python. Another common case would be anything to do with arrays that isn't too speed critical. With list comprehensions and other functional programming tools it's often very easy to search, rearrange and manipulate lists of things. Or if you want to venture into more esoteric areas like machine learning then Python makes that relatively easy to play around with.
--
Jobless
Jobless
- tamte
- Member
- 8833 posts
- Joined: July 2007
- Offline
muttoabthis is the question most users had when H9 came out with Python support
What advantage is python for use like this primarily as expressions in nodes? To me, there is far greater complexity and risk of error over HScript (assuming most usage is simple like this)? Is HScript being completely deprecated?
14years later and Hscript is still going strong for parameter expressions, you dont have to worry about it being deprecated
to me longer syntax and also at the time (or still?) much slower execution speed than HScript were not worth using Python as a primary expression language
so as has already been said, you would use it when it's more convenient
muttoabdefinitely worth learning though, knowing Python is invaluable
but I'm wondering if it's worth the learning effort for a small (i.e. one man... aka me) studio like mine.
Edited by tamte - Oct. 1, 2021 04:41:47
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- Andr
- Member
- 899 posts
- Joined: Feb. 2016
- Offline
- Soothsayer
- Member
- 874 posts
- Joined: Oct. 2008
- Offline
Andrch(opinputpath(".",0)+"/target_type")=="targetmeshsize"
Is there a way in HScript to do this kind of string evaluation, to drive a Switch Node?
I'm able to do it only in Python.target = hou.pwd().parent().parm('target_type').eval() if target == "targetmeshsize": return 1 else: return 0
?
--
Jobless
Jobless
- tamte
- Member
- 8833 posts
- Joined: July 2007
- Offline
AndrHScript:
Is there a way in HScript to do this kind of string evaluation, to drive a Switch Node?
I'm able to do it only in Python.target = hou.pwd().parent().parm('target_type').eval() if target == "targetmeshsize": return 1 else: return 0
strcmp(chs("../target_type"), "targetmeshsize")==0
that being said you can also simplify your Python, since for expresions you can use ch() to get parm value in Python too
Python:
ch("../target_type")=="targetmeshsize"
Edited by tamte - Oct. 1, 2021 11:56:12
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- muttoab
- Member
- 10 posts
- Joined: July 2005
- Offline
- Andr
- Member
- 899 posts
- Joined: Feb. 2016
- Offline
tamte
that being said you can also simplify your Python, since for expresions you can use ch() to get parm value in Python too
Python:ch("../target_type")=="targetmeshsize"
this is the simplest one liner to return 0 and 1. I'm now using all the time!
I was wondering, what if you want return different values in such simple way?
This doesn't seem to work:
return 3 if ch("../target_type")=="targetmeshsize" else 10
Edited by Andr - Sept. 10, 2022 12:43:57
- yeatshai
- Member
- 14 posts
- Joined: Jan. 2011
- Online
-
- Quick Links