- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there, I am trying to split code into modules, and make them all accessible from a single GUI.
Ran into an issue where I need to pass user input from the GUI to an imported module class.
The problem is that the result is always 0 when the module runs, I cannot work out why this would be.
Here is a recreation highlighting the problem:
--------------------------------------------------
class Example
def __init__(self, user_input):
self.user_input = user_input
def function(self, *args):
print('The example class dictates that ' + str(self.user_input) + ' was your number.')
---------------------------------------------------
import maya.cmds as mc
import example_class
class Window(object):
def __init__(self):
self.window = 'Window'
self.title = 'Title'
self.size = (400, 400)
if mc.window(self.window, ex=True):
mc.deleteUI(self.window, window=True)
self.window = mc.window(self.window, t=self.title, wh=self.size)
mc.columnLayout(adj=True)
self.number = mc.intSliderGrp(l='Pick a Number:', adj=True, min=1, max=100, field=True)
result = mc.intSliderGrp(self.number, q=True, v=True)
my_example_class = example_class.Example(result)
mc.button(l='Print number from this class', c=self.print_result)
mc.button(l='Print number from example class', c=my_example_class.function)
mc.showWindow()
def print_result(self, *args):
class_result = mc.intSliderGrp(self.number, q=True, v=True)
print('This class dictates that ' + str(class_result) + ' was your number.')
my_window = Window()
Window()
---------------------------------------------------
If I move the slider to 63 for example, this is the print result from both functions:
"This class dictates that 63 was your number."
"The example class dictates that 0 was your number."
No doubt after this issue is (hopefully) solved I will likely run into another one straight away but this is what the learning process is all about. 🙂
Solved! Go to Solution.