Simple python callback -- what am I doing wrong?

   1552   2   1
User Avatar
Member
89 posts
Joined: April 2020
Offline
Hello All,

Here I have the world's simplest python SOP, and I've added a button to its UI that when pressed I'd expect to call main() in the python code. Instead, when pressing the button, I get the error "AttributeError:'module' object has no attribute 'main'


I've defined the UI for the button so that the callback script is

hou.pwd().hdaModule().main()

The code in the python node is simple:

node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.

# Use drop down menu to select examples.
def main():
print("in main...")

#main()

Clearly I'm doing something wrong, but I'm not sure what. All explanations would be most welcome!

Thanks very much,
Mary

Image Not Found

Attachments:
simple_but_broken.hip (89.2 KB)

User Avatar
Member
9567 posts
Joined: July 2007
Online
Python SOP code is not HDA module of Python SOP

code within Python SOP is executed when the node cooks as it's meant to modify geometry that the node owns during cooking

if you want to excecute random piece of python code, you can either use HDA and define it in HDA module, or you can even use any String Parameter and exec() function

Attachments:
simple_example.hipnc (96.8 KB)

Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
89 posts
Joined: April 2020
Offline
Oh my goodness -- that clears things up tremendously.

Thank you, Tomas!

Mary
  • Quick Links