accessing methods within python sop

   4424   6   1
User Avatar
Member
39 posts
Joined: July 2010
Offline
Hi guys!

I'm working on an python operator (sop) and want to call a method when a button
from the operator interface is clicked. this method is part of a bunch of
external python files I load in on the “Scripts” tab.

I've already called python scripts with button-clicks when the code is entered
as “PythonModule” (Scirpts Tab).


When I try to call one method of one script now, I get an error that the method doesn't exist.

the callback script is:

hou.pwd().hdaModule().readCDL()

Maybe because its not in the hdaModule??

do you know what to do?

best regards, seb
User Avatar
Member
71 posts
Joined: June 2008
Offline
Hello!
I have created a simple example for you. You can look through it.
Perhaps, you have forgotten to switch the script language. You should set Python, because Hscript is the default value.

Attachments:
pythonSOP.hipnc (54.5 KB)

Alexey Mazurenko
User Avatar
Member
39 posts
Joined: July 2010
Offline
Hi!
Thank you for your answer, but that doesn't really help me out.
The code I want to run is not in the PythonModule (look at the screenshot),
but in “section” with the name of the pythonfile. Any ideas?


Attachments:
screenshot.JPG (76.5 KB)

User Avatar
Member
71 posts
Joined: June 2008
Offline
Hello,
There are a lot of ways to do it.

1)I have created another version for you. You can look at the attached file.
I think that these pages from the documentation will be useful for you:
http://www.sidefx.com/docs/houdini11.0/hom/assetscripts [sidefx.com] (This method is described at the end of that page!)
http://www.sidefx.com/docs/houdini11.0/ref/windows/optype [sidefx.com]

2)Also, you can use a simple script for adding your contents from a file into the section called “PythonModule”:
import hou
def addSectionFromFile(hda_definition, section_name, file_name):
sections = definition.sections()
if sections.has_key(section_name):
# Save contents
contents = section.contents()
# Read the new contents
section_file = open(file_name, “r”)
# Add contents
data = ‘%s\n\n’%contents
data += section_file.read()
hda_definition.addSection(section_name, data)
section_file.close()


file_name = ‘%s/myModule.py’%hou.expandString('$HIP')
nodes = hou.selectedNodes()
for node in nodes:
definition = node.type().definition()
#
if node.type().definition() is None or node.isLocked():
continue
#
addSectionFromFile(definition, ‘PythonModule’, file_name)

3)Of course, if you would like to have your script as an external file then you should put it into “$HOUDINI_PATH/python<version>libs”. Then you can call it from “callback script”, for example:
import myModule;myModule.applyButton()
Edited by - Jan. 27, 2011 07:29:57

Attachments:
pythonSOP_A02.hipnc (59.6 KB)

Alexey Mazurenko
User Avatar
Member
39 posts
Joined: July 2010
Offline
you are my hero! THANK YOU!

I just hoped its easy like this: define a path to a python file within the asset and access the functions/methods of it

why doesn't it work like this?

…maybe I should eat the entire manual before posting questions….but
sometimes its not so easy to find the right answers


seb.
Edited by - Jan. 27, 2011 07:35:09
User Avatar
Member
71 posts
Joined: June 2008
Offline
Sorry, I have edited my post above and I have attached file with the another way. Please, read that again.
Edited by - Jan. 27, 2011 07:37:12
Alexey Mazurenko
User Avatar
Member
39 posts
Joined: July 2010
Offline
it's clear now
  • Quick Links