Its definitely possible to split up the code however you see fit. With your
current exception, it seems unlikely you would still see that exact error
after adding *args. It implies that you made the code change but didn't
reload the module and then reload the UI so it picks up the new definition.
Although, it doesn't seem particularly useful to split up this exact
example, when the other file still needs to make calls to Maya UI commands
and uses string literal names to assume the UI elements like "chk01". It
makes more sense for all the parts making the UI calls to the same simple
window to be a class. That way you can save the names of the UI elements
when you create them and use the right ones later.
class MyUI(object):
...
def ui(self):
self.chk01 = cmds.checkBox(...)
def get_chk01_state(self, *args):
cmds.checkBox(self.chk01, ...)
Justin
On Sat, Aug 18, 2018, 10:58 AM kiteh <[email protected]> wrote:
> Hi all, I am trying to split maya gui commands into another file, from the
> main code, like what you may do when dealing with PyQt.. Main code in a
> file while the UI code in another, for the sake of better maintaining the
> code.
>
> Here is my code:
>
> myUI.py
> from maya import cmds
> import myCode as my
>
> WINID = "MyUI"
>
>
> def ui():
> if cmds.window(WINID, exists=True):
> cmds.deleteUI(WINID)
>
> cmds.window(WINID, title="TestUI", width=165, height=140,
> sizeable=False, resizeToFitChildren=True)
>
> cmds.columnLayout(adjustableColumn=True)
> cmd.rowColumnLayout(numberOfColumns=3, columnAttach=[1, "right", 0],
> columnWidth=[2, 250])
>
> cmds.text(label="")
> cmds.checkBox("chk01", label="My checkbox 01",
> value=True, changeCommand=my.get_state)
> cmds.text(label="")
>
> cmds.showWindow(WINID)
>
> myCode.py
> from maya import cmds
>
> def get_state(*args):
> check_state = cmds.checkBox("chk01", value=True, query=True)
> print check_state
>
>
> When I tried to uncheck the option in the UI, I got the following error:
> # Error: get_state() takes no arguments (1 given)
> # TypeError: get_state() takes no arguments (1 given) #
>
>
> Tried adding in `*args` into the `get_state()` but getting the same error.
> Is it possible to do so when dealing with only maya code?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/4e7d9dea-a1de-4b9b-a01d-ad27c62e8de5%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/4e7d9dea-a1de-4b9b-a01d-ad27c62e8de5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1S7b4x%2B4nq8FJaEaX3pWrCjaorKe7DS34jGFa-7AhG2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.