workspaceControl error

Anonymous

workspaceControl error

Anonymous
Not applicable

I've been trying to adapt the example code in the workspaceControl documentation into a class and haven't been able to do it. Here is the documentation code:

import maya.cmds as cmds
def createCustomWorkspaceControlUI(*args):
cmds.columnLayout()
cmds.button()
cmds.button()
cmds.button()

cmds.workspaceControl("myCustomWorkspaceControl", retain=False, floating=True, uiScript="createCustomWorkspaceControlUI()");

And here is a simplification of how I adapted it:

import maya.cmds as cmds
class ui(object):
    def build(self):
        if cmds.workspaceControl("myCustomWorkspaceControl", exists=1):
                cmds.deleteUI("myCustomWorkspaceControl")
        self.wS = cmds.workspaceControl("myCustomWorkspaceControl", retain=False, floating=True, uiScript="createCustomWorkspaceControlUI");
    def createCustomWorkspaceControlUI(self, *args):
        print("1")
o = ui()
o.build()

When I execute the previous code I get the following error:

# Error: line 1: NameError: file <maya console> line 1: name 'createCustomWorkspaceControlUI' is not defined #

On the other hand, if you execute inside of Maya

def createCustomWorkspaceControlUI(self, *args):
    print("1")

and then execute my adapted code it will work. The documentation and errors I've been getting tell me that uiScript only accepts two kinds of input: strings and functions. I believe that methods inside a class are not accepted by the uiScript as they are technically not the same as functions. Am I wrong? Is my only solution to turn the whole ui creation into a function not part of my UI class?

 

Thank you in advance

0 Likes
Reply
Accepted solutions (1)
978 Views
3 Replies
Replies (3)

onefabis
Participant
Participant
Accepted solution

Perhaps you better to call it in this way 

 

import maya.cmds as cmds
class ui(object):
	def __init__(self):
		if cmds.workspaceControl("myCustomWSP", exists=1):
			cmds.deleteUI("myCustomWSP")
		
	def createCustomWorkspaceControlUI(self,*args):
		print args[1]
			    
	def build(self):
		cmds.workspaceControl("myCustomWSP", uiScript="ui().createCustomWorkspaceControlUI(%s,%s)" %(10,20), retain=1, floating=1 )
			
ui().build()

I also wrote some numbers so you can really pass any variables to your 'createCustomWorkspaceControlUI' function

 

Anonymous
Not applicable

Though similar to your suggestion the real solution was as follows:

 

import maya.cmds as cmds
class ui(object):
    def one(self):
        if cmds.workspaceControl("newControl", exists=1):
                cmds.deleteUI("newControl")
        self.wS = cmds.workspaceControl("newControl", retain=False, floating=True, uiScript="ui.two()");
    @classmethod
    def two(cls):
        print("2")
        
ui().one()

The position of the methods don't really affect the output and the @classmethod is required for it to work!

Thanks for leading me to the correct solution!

0 Likes

Anonymous
Not applicable

Can't edit nor delete my reply so I have, to repost... ignore the @classmethod solution I gave it works but gives more problems than it solves them. The solutionI've accepted is the best way to solve it.

0 Likes