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
accessing methods within python sop
4424 6 1- 3Dude
- Member
- 39 posts
- Joined: July 2010
- Offline
- archie
- Member
- 71 posts
- Joined: June 2008
- Offline
- 3Dude
- Member
- 39 posts
- Joined: July 2010
- Offline
- archie
- 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()
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
Alexey Mazurenko
- 3Dude
- 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.
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
- archie
- Member
- 71 posts
- Joined: June 2008
- Offline
- 3Dude
- Member
- 39 posts
- Joined: July 2010
- Offline
-
- Quick Links