Callback script and hscript

   2492   8   2
User Avatar
Member
266 posts
Joined: Feb. 2016
Offline
Hello,
How can I use the callback script of an hda to run a hscript script saved in the scripts section? If it lets you type a custom hscript there, surely there must be a way to use it? If you are wondering why I am not using python, its because I plan to use opscript command to print a huge list of commands that I need to execute to re-build a network/certain parameters. that is also why I want to save the script under lists. Its easy to edit a bigger scripts there then on the callback script section which is just one line. I have seen plenty of info on how to do that in python, but how can I do this in hscript?
Thanks
Edited by evanrudefx - Nov. 7, 2023 16:55:47

Attachments:
hs.png (159.7 KB)
hs2.png (75.0 KB)

Thanks,

Evan
User Avatar
Member
247 posts
Joined: May 2017
Offline
Hey, what works for me to access the expression section of the HDA, is for example:
opdef:.?Expressions

The same applies when embedding custom scripts/files:
opdef:.?test.txt

Edited by vikus - Nov. 8, 2023 06:35:09

Attachments:
hscript-hda-section.png (20.0 KB)

User Avatar
Member
266 posts
Joined: Feb. 2016
Offline
Thanks so much!
Thanks,

Evan
User Avatar
Member
266 posts
Joined: Feb. 2016
Offline
I was wondering, how can I do the same thing in python? I switched from hscript to python, so of course that doesn't work anymore.
Thanks,

Evan
User Avatar
Member
247 posts
Joined: May 2017
Offline
evanrudefx
I was wondering, how can I do the same thing in python? I switched from hscript to python, so of course that doesn't work anymore.

Hey, in python:
hou.phm().foo()
phm is the shortcut for hou.pwd().hdaModule() (Currents Node Python module).

foo() is any function from your HDA Python module. Simply select the PythonModule in HDA under Scripts and define a function:
def foo():
     print('hello')

You can also define your function in the Session Module and then call your callback like this:
hou.session.foo()
Edited by vikus - Nov. 10, 2023 16:36:00
User Avatar
Member
266 posts
Joined: Feb. 2016
Offline
viklc
def foo():
print('hello')
i'll be honest, I don't really don't know what I am doing. But in this case that won't work. I am trying to do something that accesses
kwargs["node"]
. Anytime I use that in the python module it gives me an error. In this case I just want to write a python script and run the script in the callback section. FYI I know what I am writing works because I wrote the same script accessing
kwargs["node"]
in a oncreated script. It also works directly in the callback script section. But the same thing doesn't work in the python module.
Edited by evanrudefx - Nov. 10, 2023 16:42:54
Thanks,

Evan
User Avatar
Member
247 posts
Joined: May 2017
Offline
The python module kwargs dictionary only passes the node type. You can test this simply by calling print(kwargs). If you need the reference to the current node in the python module, use:
node = hou.pwd()
instead of
node = kwargs['node']
Edited by vikus - Nov. 10, 2023 16:49:56
User Avatar
Member
266 posts
Joined: Feb. 2016
Offline
viklc
The python module kwargs dictionary only passes the node type. You can test this simply by calling print(kwargs). If you need the reference to the current node in the python module, use:
node = hou.pwd()
instead of
node = kwargs['node']
Thanks so much. Amazing. I got it working.
Edited by evanrudefx - Nov. 10, 2023 17:10:43
Thanks,

Evan
User Avatar
Member
247 posts
Joined: May 2017
Offline
evanrudefx
Thanks so much. Amazing. I got it working.
You're welcome.
  • Quick Links