2

I'm creating a custom floating window, where I can have buttons like a shelf, that call and run scripts for me. Very useful for modeling artists like myself who don't do a lot of scripting! :P I'm hoping to resolve this without having to modify Script_B too much but we'll see what has to be done! :D

So as it stands I have two scripts, Script_A and Script_B. Script B is saved out as "my_custom_script_name.py". I'm trying to run it using Script_A, but the variables are never defined properly.

When I run Script_A with Script_B saved out in the proper place, the UI doesn't even load because it errors out on the first variable defined.

# Error: NameError: file C:/Users/polyshifter/Documents/maya/2019/prefs/scripts\my_custom_script_name.py line 2: global name 'mc' is not defined # 

So we haven't even gotten to the other variables yet and it's broken.

SCRIPT A

import maya.cmds as mc
import maya.mel as mel

# Create a custom floating window with 
if mc.window('ToolsWindow', q=True, exists=True):
    mc.deleteUI('ToolsWindow')
if mc.workspaceControl('ToolsWorkspaceControl', q=True, exists=True):
    mc.deleteUI('ToolsWorkspaceControl')
mc.window('ToolsWindow')
mc.tabLayout('ToolsTabs')

###IMPORT PANEL###

tabMenu = mc.columnLayout("Menu", adj=True)
separator_long = mc.separator(
                         height=10,
                         style='in')


mc.button(label="MyCustomScript", command = "my_custom_script_com()")

mc.setParent('..')
mc.showWindow()

#### My custom script ####
def my_custom_script_com(*args):
    import my_custom_script_name
    my_custom_script_name.run_my_custom_script_ui()

SCRIPT B

def run_my_custom_script_ui():
    import maya.cmds as mc
    if mc.window('my_script_ui', q=True, exists=True):
        mc.deleteUI('my_script_ui')
    else:
        mc.window('my_script_ui')

    mc.columnLayout("Menu", adj=True)

    mc.button(label="Please_print", command = "please_print()")

    mc.setParent('..')
    mc.showWindow()
    def please_print():
        print "OMG IT'S FINALLY WORKING!! YAY!!"

I have tried placing Script_B within Script_A at the very end of the script like:

def my_custom_script_com(*args):
    import maya.cmds as mc
    if mc.window('my_script_ui', q=True, exists=True):
        mc.deleteUI('my_script_ui')
    else:
        mc.window('my_script_ui')

    mc.columnLayout("Menu", adj=True)

    mc.button(label="Please_print", command = "please_print()")

    mc.setParent('..')
    mc.showWindow()
    def please_print():
        print "OMG IT'S FINALLY WORKING!! YAY!!"

In which the first UI loads, and then the second, and I see my button, but when I click it I get:

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

I apologize if there's too much unneeded code or anything I tried to cut it to bare bones as much as I could. It's my first question here!

Any help on making these variables work properly would be amazing! <3 Thank you in advance!

Thank you so much for the help everyone! Theodox was able to resolve this issue flawlessly!

However.... the issue persists in my non simplified script!

I have a script from this artist, Leonardo Lezzi. "https://www.linkedin.com/pulse/super-bool-tool-python-leonardo-iezzi/" When I take his script and try to implement it into mine, it causes errors. First pma isn't defined, and then after that none of his definitions are defined.

I have tried making his UI's (the tutorial one and the main one) and defining them into commands, but that also hasn't worked out for me. The reason is because (from what I've learned today :D), maya doesn't have the functions anymore, after the Script_B (the now boolean script) is called.

The only method I've found to work, is to put the boolean script inside my main one so it lives with it. Then define his UI's as commands, and then list those 2 commands with my button click from ScriptA. And then run it. But THEN go back and delete the definitions in the script and unindent and then rerun the script. So that the definitions are still defined from running previously but now the ui is being made globally... Obviously this breaks when you restart maya and I'm TOTALLY missing the point as to how to make them defined, while still being callable (is that right?) when I click the button.

This clearly is a hack and a stupid way of doing it, but I don't understand how to get the "super bool tool" to run from my script, only by sourcing the super_bool_tool.py

Below is what I have so far but again the idea here is NOT to run this inside my shelf ui script. I want to call the python script so it can live on its own.

import maya.cmds as mc
import maya.mel as mel
import pymel.all as pma

BOOLEANMODE_ADD = 1
BOOLEANMODE_SUBTRACT = 2
PRIMITIVE_CUBE = 0
PRIMITIVE_CYLINDER = 1
PRIMITIVE_SPHERE = 2
PRIMITIVE_CUSTOM = 3


def cleanUp ():
    pma.delete (constructionHistory=True)
    #pma.select ()
    pma.delete ("*_ctrl*")

def hider(option):
    if (option == 0):
        pma.hide ()
    elif (option == 1):
        pma.select ("*_ctrl*")
        pma.hide ()
    elif (option == 2):
        pma.select ("*_ctrl*")
        pma.showHidden ()
        pma.select (clear=True)

def fixMaterial():
    pma.hyperShade( assign="lambert1" )

def triangulate():
    pma.polyTriangulate()

def creator(primitives):
    selection = pma.ls(sl=True)
    for x in selection:

        if primitives == PRIMITIVE_CUBE:
            a = makeCube() #Create cube
        if primitives == PRIMITIVE_CYLINDER:
            a = makeCyl() #Create cyl 
        if primitives == PRIMITIVE_SPHERE:
            a = makeSphere() #Create sphere 
        if primitives == PRIMITIVE_CUSTOM:
            a = selection[1]  
            x = selection[0]
            pma.select (a)
        b = createController(a)
        meshConstrainer (b,a)
        operator(x,a) 
        pma.select (b)    


def operator(meshA, meshB):
   booleanmode = get_boolean_mode()
   pma.polyBoolOp( meshA, meshB, op=booleanmode, n="basemesh" )
   pma.hyperShade( assign="lambert1" )   #REMINDER: Need to be replaced with the actual assigned material and not with a lambert1 so for who is working with other materials can easyly keep using that


def get_boolean_mode():
    if pma.radioButton(addRadioB, query = True, select = True) :
        return BOOLEANMODE_ADD
    if pma.radioButton(subRadioB, query = True, select = True) :
        return BOOLEANMODE_SUBTRACT
    return None

def makeCube():
    cubeTransform = pma.polyCube(n="cubetobool", w=1, h=1, d=1, sx=1, sy=1, sz=1)[0]   
    return cubeTransform       

def makeCyl():
    cylTransform = pma.polyCylinder(n="cubetobool", r=1, h=2, sx=20)[0]   
    return cylTransform   

def makeSphere():
    sphereTransform = pma.polySphere(n="cubetobool", r=1, sx=20, sy=20, cuv=2)[0]   
    return sphereTransform    


def meshConstrainer(constrainer, constrained):   
    pma.scaleConstraint( constrainer, constrained, maintainOffset=True)
    pma.parentConstraint( constrainer, constrained, maintainOffset=True)


def createController(object):
    #object = pma.ls(sl=True) 
    pivotObj = pma.xform(object,query=True,t=True,worldSpace=True)
    edges = pma.filterExpand(pma.polyListComponentConversion(te=1),sm=32,ex=1) # convert edges to curve ancd create one object
    for edge in edges:
        vtx = pma.ls(pma.polyListComponentConversion(edge,fe=1,tv=1),fl=1)
        p1 = pma.pointPosition(vtx[0])
        p2 = pma.pointPosition(vtx[1])
        curves = pma.curve(n="line_ctrl_curve", d=1,p=(p1,p2))

    ctrl = pma.curve (n="bool_ctrl", d=1,ws=True, p=pivotObj)
    pma.xform (centerPivots=True)
    for curveEdge in pma.ls ("line_ctrl*"):
        pma.parent(curveEdge,ctrl, s=1, r=1)
        pma.rename(curveEdge, "shapeunused")


    transforms =  pma.ls(type='transform')
    deleteList = []
    for tran in transforms:
        if pma.nodeType(tran) == 'transform':
            children = pma.listRelatives(tran, c=True) 
            if children is None:
                #print '%s, has no childred' %(tran)
                deleteList.append(tran)

    if not deleteList:           
       pma.delete(deleteList)       
    return ctrl




#################TUTORIAL
def super_bool_tut():
    windowNameTut = "Tutorial"
    if (pma.window(windowNameTut , exists=True)):
        pma.deleteUI(windowNameTut) 
    windowTutorial = pma.window(windowNameTut, title = windowNameTut, width = 400, height = 300, backgroundColor = [0.2, 0.2, 0.2])
    pma.columnLayout( "testColumn", adjustableColumn = True)
    pma.text("intro", label = "This tool is a super tool to make booleans wrote by Leonardo Iezzi. To make it works correctly, you need to have your base mesh already even if just a cube. With your base mesh selected just press one of the three buttons on the windows to subtract or add those primitives. If you want to use a custom mesh for the operation: select your base mesh then the custom one (it's important to pick your base mesh first) and then press the 'Use custom mesh' button. After you have done, select your base mesh and press 'Clean Up.'",wordWrap= True, height = 100, backgroundColor = [0.2, 0.2, 0.2], align='left', parent = "testColumn")

     #pma.text("first", label = "1- Select always your main mesh first",wordWrap= True, height = 40, backgroundColor = [0.2, 0.2, 0.2], align='left', parent = "testColumn")
     #pma.text("secondo", label = "2- In case you want to use a custom mesh: Select first your main mesh then the mesh you want to add or subtract",wordWrap= True, height = 40, backgroundColor = [0.2, 0.2, 0.2], align='left', parent = "testColumn")
     #pma.text("third", label = "3- Everythong should works",wordWrap= True, height = 40, backgroundColor = [0.2, 0.2, 0.2], align='left', parent = "testColumn")



    pma.separator(parent = "testColumn", height=20)
    pma.button("goit", label = "Got it", width = 120, height = 40, backgroundColor = [0.5, 0.5, 0.5], parent = "testColumn", command = "pma.deleteUI(windowNameTut)")

    pma.showWindow()

################################################################################################UI################################################# 
# @@@@@@@    THIS IS POLYSHIFTER!! I HAVE ADDED THIS AS A FUNCTION INSTEAD OF LEAVING IT UNINDENTED
def super_bool_ui():
    windowName = "SuperBool"
    windowSize = (120, 200)
    if (pma.window(windowName , exists=True)):
        pma.deleteUI(windowName)
    window = pma.window( windowName, title= windowName, width = 120, height = 200 )
    pma.columnLayout( "mainColumn", adjustableColumn = True)

    ################################################################################################UI#################################################
    pma.gridLayout("nameGridLayout01", numberOfRowsColumns = (1,4), cellWidthHeight = (40,40), parent = "mainColumn")
    pma.symbolButton("nameButton1", image = "polyCube.png", width = 40, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout01", command = "creator(PRIMITIVE_CUBE)")
    pma.symbolButton("nameButton2", image = "polyCylinder.png", width = 40, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout01", command = "creator(PRIMITIVE_CYLINDER)")
    pma.symbolButton("nameButton3", image = "polySphere.png", width = 40, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout01", command = "creator(PRIMITIVE_SPHERE)")
    pma.columnLayout("columnLayoutName01", adjustableColumn = True, backgroundColor = [0.2, 0.2, 0.2])
    pma.radioCollection("collection10", parent = "columnLayoutName01")
    subRadioB = pma.radioButton("subRadio", select = True, label = "Sub")
    addRadioB = pma.radioButton("addRadio", label = "Add")
    pma.setParent( '..' )
    pma.setParent( '..' )
    ################################################################################################UI#################################################
    pma.separator(parent = "mainColumn", height=20)

    pma.button("customMeshB", label = "Use Custom Mesh", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "mainColumn", command = "creator(PRIMITIVE_CUSTOM)")

    pma.separator(parent = "mainColumn", height=20)
    ################################################################################################UI#################################################
    pma.gridLayout("nameGridLayout03", numberOfRowsColumns = (1,3), cellWidthHeight = (53,40), parent = "mainColumn")
    pma.button("hidSelB", label = "Hide Sel",  height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout03", command = "hider(0)")
    pma.button("hidAllB", label = "Hide All",  height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout03", command = "hider(1)")
    pma.button("showAll", label = "Show All",  height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout03", command = "hider(2)")

    pma.separator(parent = "mainColumn", height=20)

    pma.button("clean", label = "Clean Up", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "mainColumn", command = "cleanUp()")

    pma.separator(parent = "mainColumn", height=20)
    ################################################################################################UI#################################################
    ################################################################################################UI#################################################
    pma.gridLayout("nameGridLayout02", numberOfRowsColumns = (1,2), cellWidthHeight = (80,40), parent = "mainColumn")
    pma.button("triangB", label = "Triangulate", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout02", command = "triangulate()")
    pma.button("fixMatB", label = "FixMaterial", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = "nameGridLayout02", command = "fixMaterial()")
    ################################################################################################UI#################################################
    pma.showWindow()


###################################################################
##################                              ###################
##################    END OF SUPER BOOL TOOL    ###################
##################                              ###################
###################################################################
###################################################################
##################                              ###################
##################   BEGINNING OF MY UI SCRIPT  ###################
##################                              ###################
###################################################################

# Create a custom floating window with 
if mc.window('ToolsWindow', q=True, exists=True):
    mc.deleteUI('ToolsWindow')
if mc.workspaceControl('ToolsWorkspaceControl', q=True, exists=True):
    mc.deleteUI('ToolsWorkspaceControl')
mc.window('ToolsWindow')
mc.tabLayout('ToolsTabs')

#########################################################
##################    IMPORTING PANEL    ################
#########################################################
tabMenu = mc.columnLayout("Menu", adj=True)
separator_long = mc.separator(
                         height=10,
                         style='in')


mc.button(label="MyCustomScript", command = "my_custom_script_com()")

mc.setParent('..')
mc.showWindow()

#### My custom script ####
def my_custom_script_com(*args):
    super_bool_tool_ui()
    super_bool_tool_tut()
  • I haven't read everything but for the error with `please_print` not being defined you might just need to move the definition outside your `my_custom_script_com` function. Just un-tab those last 2 lines and see if that works! – Hoog May 14 '19 at 19:36

3 Answers3

1

If I am understanding correctly, then you can get the second approach to work by moving your function. Something like:

def my_custom_script_com(*args):
    import maya.cmds as mc
    if mc.window('my_script_ui', q=True, exists=True):
        mc.deleteUI('my_script_ui')
    else:
        mc.window('my_script_ui')

    mc.columnLayout("Menu", adj=True)

    def please_print(): # define your function here
        print "OMG IT'S FINALLY WORKING!! YAY!!"

    mc.button(label="Please_print", command = "please_print()") # use the function

    mc.setParent('..')
    mc.showWindow()

This is because functions must be defined before they can be called. Hope this helps solve your problem! I've also never used maya, but i know in tkinter the command would be tkinter.Button(label="Please_print", command=please_print) without quotes on please_print. Not sure if this is applicable here or not!

If you would prefer to move please_print() to the global space you would dedent that section into its own function (as opposed to a subfunction of a function which is pretty atypical). It would look like:

# make a global function
def please_print():
    print "OMG IT'S FINALLY WORKING!! YAY!!"

def my_custom_script_com(*args):
    import maya.cmds as mc
    if mc.window('my_script_ui', q=True, exists=True):
        mc.deleteUI('my_script_ui')
    else:
        mc.window('my_script_ui')

    mc.columnLayout("Menu", adj=True)

    mc.button(label="Please_print", command = "please_print()") # use the function

    mc.setParent('..')
    mc.showWindow()

Or perhaps the best (using tkinter notation) would be:

# make a global function
def please_print():
    print "OMG IT'S FINALLY WORKING!! YAY!!"

def my_custom_script_com(*args):
    import maya.cmds as mc
    if mc.window('my_script_ui', q=True, exists=True):
        mc.deleteUI('my_script_ui')
    else:
        mc.window('my_script_ui')

    mc.columnLayout("Menu", adj=True)

    mc.button(label="Please_print", command = please_print) # assign function without quotes or parenthesis

    mc.setParent('..')
    mc.showWindow()
Reedinationer
  • 5,661
  • 1
  • 12
  • 33
  • I don't believe this will work because the string form of the command expects the command to be defined in the global namespace -- it may work in testing and fail in production because the user probably tries to define please_print interactively in their own session but users don't have it. The tk example is similar to the correct way to do it in Maya. – theodox May 14 '19 at 19:42
  • @theodox OK I added an example of defining it in the global space, as well as how to implement the `tkinter` notation since you have said it is similar! Thanks for the info, as I said I have never used `maya` – Reedinationer May 14 '19 at 19:48
  • thank you so much for posting this did help me understand some lessons :D – PolyShifter May 14 '19 at 20:58
1

This is a maya perennial issue. The problem is that you're using the string name of the command:

command = "please_print()"

But 'please_print' is inside run_my_custom_script_ui and it falls out of scope when the function runs. There is no 'please_print' function for Maya to call when you click the button.

If you reverse the order and pass the function object itself, without quotes, you should be OK (by adding the function to the button, you ensure that it does not fall out of scope and go away:

# this import does not need to be inside the function
import maya.cmds as mc

def run_my_custom_script_ui():

    # define this up here so it's in scope
    # when you want to call it below.  The *_
    # argument lets you ignore the default
    # argument which buttons always fire in Python

    def please_print(*_):
        print "OMG IT'S FINALLY WORKING!! YAY!!"

    if mc.window('my_script_ui', q=True, exists=True):
        mc.deleteUI('my_script_ui')
    else:
        mc.window('my_script_ui')

    mc.columnLayout("Menu", adj=True)

    mc.button(label="Please_print", command = please_print)

    mc.setParent('..')
    mc.showWindow()

More here: https://theodox.github.io/2014/maya_callbacks_cheat_sheet

theodox
  • 12,028
  • 3
  • 23
  • 36
  • Thanks for posting here! I have been working on this ever since you posted your answer! I actually ready your github before coming here and I'm shocked you posted a reply on my question! haha so thank you! At first I couldn't understand why this worked for this example, but not on a more complex one (I still don't fully understand why it's not working on another script). But using your post, and your github, I ended up getting the other issue resolved by bringing it all into my main script. Which isn't ideal. If you could look at my new information I'd greatly appreciate it. – PolyShifter May 14 '19 at 20:58
  • I have just updated my original question with the added info. If you have any time to potentially help with this, I have learned SO MUCH already, haha thank you thank you thank you. – PolyShifter May 14 '19 at 21:18
0

I have corrected lots of things in you script, try to have a look to it. There is so many things going on in your script that I'll put few links below : How to use a slider value in calculations?

One thing that I might have not said on other topic is, dont use pymel if your are just using it as maya.cmds Pymel is really cool but it is really slow.

Also if you are separatig your script into 'superbool.py', it should work by doing :

import superbool
superbool.super_bool_ui()

Finally try to avoid strings to make links for commands or ui element. Try to use variables, dict, class !


import maya.cmds as mc
import pymel.all as pma
from functools import partial

BOOLEANMODE_ADD = 1
BOOLEANMODE_SUBTRACT = 2
PRIMITIVE_CUBE = 0
PRIMITIVE_CYLINDER = 1
PRIMITIVE_SPHERE = 2
PRIMITIVE_CUSTOM = 3


def cleanUp ():
    mc.delete(constructionHistory=True)
    mc.delete("*_ctrl*")

def hider(option, *args):
    if option == 0:
        mc.hide()
    elif option == 1:
        mc.select ("*_ctrl*")
        mc.hide()
    elif option == 2:
        mc.select ("*_ctrl*")
        mc.showHidden()
        mc.select (clear=True)

def fixMaterial():
    # pma.hyperShade( assign="lambert1" )
    # works better with the command sets, jut put the SG you need
    sel = mc.ls(sl = True)
    if not mc.objExists('grey20'):
        shaLambert = mc.shadingNode('lambert', asShader = True, name = 'grey20')
        shaLambertSG = mc.sets(name = 'grey20SG', empty = True, renderable = True, noSurfaceShader = True)
        mc.connectAttr('grey20.outColor', 'grey20SG.surfaceShader')
    mc.sets(sel, edit = True, fe = shaLambertSG)

def triangulate():
    mc.polyTriangulate()

def creator(primitives, *args):
    selection = mc.ls(sl=True)
    for x in selection:
        if primitives == PRIMITIVE_CUBE:
            a = makeCube() #Create cube
        if primitives == PRIMITIVE_CYLINDER:
            a = makeCyl() #Create cyl 
        if primitives == PRIMITIVE_SPHERE:
            a = makeSphere() #Create sphere 
        if primitives == PRIMITIVE_CUSTOM:
            a = selection[1]  
            x = selection[0]
            mc.select(a)
        b = createController(a)
        meshConstrainer (b,a)
        operator(x,a) 
        mc.select(b)

def operator(meshA, meshB):
   booleanmode = get_boolean_mode()
   # is there a way to replace this pymel ?
   pma.polyBoolOp( meshA, meshB, op=booleanmode, n="basemesh" )
   fixMaterial()  #REMINDER: Need to be replaced with the actual assigned material and not with a lambert1 so for who is working with other materials can easyly keep using that


def get_boolean_mode(addRadioB=None, subRadioB=None):
    # should not be implemented as string.....
    if mc.radioButton('addRadio', query = True, select = True) :
        return BOOLEANMODE_ADD
    if mc.radioButton('subRadio', query = True, select = True) :
        return BOOLEANMODE_SUBTRACT
    return None

def makeCube():
    cubeTransform = mc.polyCube(n="cubetobool", w=1, h=1, d=1, sx=1, sy=1, sz=1)[0]
    return cubeTransform       

def makeCyl():
    cylTransform = mc.polyCylinder(n="cubetobool", r=1, h=2, sx=20)[0]
    return cylTransform   

def makeSphere():
    sphereTransform = mc.polySphere(n="cubetobool", r=1, sx=20, sy=20, cuv=2)[0]
    return sphereTransform    


def meshConstrainer(constrainer, constrained):   
    mc.scaleConstraint( constrainer, constrained, maintainOffset=True)
    mc.parentConstraint( constrainer, constrained, maintainOffset=True)


def createController(object):
    #object = pma.ls(sl=True) 
    pivotObj = mc.xform(object,query=True,t=True,worldSpace=True)
    edges = mc.filterExpand(mc.polyListComponentConversion(te=1),sm=32,ex=1) # convert edges to curve ancd create one object
    for edge in edges:
        vtx = mc.ls(mc.polyListComponentConversion(edge,fe=1,tv=1),fl=1)
        p1 = mc.pointPosition(vtx[0])
        p2 = mc.pointPosition(vtx[1])
        curves = mc.curve(n="line_ctrl_curve", d=1,p=(p1,p2))

    ctrl = mc.curve (n="bool_ctrl", d=1,ws=True, p=pivotObj)
    mc.xform (centerPivots=True)
    for curveEdge in mc.ls ("line_ctrl*"):
        mc.parent(curveEdge,ctrl, s=1, r=1)
        mc.rename(curveEdge, "shapeunused")


    transforms =  mc.ls(type='transform')
    deleteList = []
    for tran in transforms:
        if mc.nodeType(tran) == 'transform':
            children = mc.listRelatives(tran, c=True)
            if children is None:
                #print '%s, has no childred' %(tran)
                deleteList.append(tran)

    if not deleteList:           
       mc.delete(deleteList)
    return ctrl


def deleteUI(name, *args):
    mc.deleteUI(name)


#################TUTORIAL
def super_bool_tut():
    windowNameTut = "Tutorial"
    if mc.window(windowNameTut , exists=True):
        mc.deleteUI(windowNameTut)
    windowTutorial = mc.window(windowNameTut, title = windowNameTut, width = 400, height = 300, backgroundColor = [0.2, 0.2, 0.2])
    mainSubLayout = mc.columnLayout( "testColumn", adjustableColumn = True)
    lb_txt = "This tool is a super tool to make booleans wrote by Leonardo Iezzi. To make it works correctly, you need to have your base mesh already even if just a cube. "
    lb_txt += "With your base mesh selected just press one of the three buttons on the windows to subtract or add those primitives. "
    lb_txt += "If you want to use a custom mesh for the operation: select your base mesh then the custom one "
    lb_txt += "(it's important to pick your base mesh first) and then press the 'Use custom mesh' button. After you have done, select your base mesh and press 'Clean Up.'"
    mc.text("intro", label = lb_txt ,wordWrap= True, height = 100, backgroundColor = [0.2, 0.2, 0.2], align='left', parent = mainSubLayout)

    mc.separator(parent = "testColumn", height=20)
    mc.button("goit", label = "Got it", width = 120, height = 40, backgroundColor = [0.5, 0.5, 0.5], parent = mainSubLayout, command = partial(deleteUI, windowNameTut))

    mc.showWindow()

################################################################################################UI################################################# 
# @@@@@@@    THIS IS POLYSHIFTER!! I HAVE ADDED THIS AS A FUNCTION INSTEAD OF LEAVING IT UNINDENTED
def super_bool_ui():
    windowName = "SuperBool"
    w, h = (120, 200)
    if mc.window(windowName , exists=True):
        mc.deleteUI(windowName)
    window = mc.window( windowName, title= windowName, width = w, height = h)
    mainLayout = mc.columnLayout( "mainColumn", adjustableColumn = True)

    ################################################################################################UI#################################################
    gridl_01 = mc.gridLayout("nameGridLayout01", numberOfRowsColumns = (1,4), cellWidthHeight = (40,40), parent = mainLayout)
    btn_symb = mc.symbolButton("nameButton1", image = "polyCube.png", width = 40, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_01, command = partial(creator, PRIMITIVE_CUBE))
    mc.symbolButton("nameButton2", image = "polyCylinder.png", width = 40, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_01, command = partial(creator, PRIMITIVE_CYLINDER))
    mc.symbolButton("nameButton3", image = "polySphere.png", width = 40, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_01, command = partial(creator, PRIMITIVE_SPHERE))
    vl_column01 = mc.columnLayout("columnLayoutName01", adjustableColumn = True, backgroundColor = [0.2, 0.2, 0.2], p=mainLayout)
    mc.radioCollection("collection10", parent = vl_column01)
    subRadioB = mc.radioButton("subRadio", select = True, label = "Sub")
    addRadioB = mc.radioButton("addRadio", label = "Add")
    ################################################################################################UI#################################################
    mc.separator(parent = mainLayout, height=20)

    mc.button("customMeshB", label = "Use Custom Mesh", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = mainLayout, command = partial(creator, PRIMITIVE_CUSTOM))

    mc.separator(parent = mainLayout, height=20)
    ################################################################################################UI#################################################
    gridl_02 = mc.gridLayout("nameGridLayout03", numberOfRowsColumns = (1,3), cellWidthHeight = (53,40), parent = mainLayout)
    mc.button("hidSelB", label = "Hide Sel",  height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_02, command = partial(hider, 0))
    mc.button("hidAllB", label = "Hide All",  height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_02, command = partial(hider, 1))
    mc.button("showAll", label = "Show All",  height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_02, command = partial(hider, 2))

    mc.separator(parent = mainLayout, height=20)

    mc.button("clean", label = "Clean Up", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = mainLayout, command = cleanUp)

    mc.separator(parent = mainLayout, height=20)
    ################################################################################################UI#################################################
    ################################################################################################UI#################################################
    gridl_03 = mc.gridLayout("nameGridLayout02", numberOfRowsColumns = (1,2), cellWidthHeight = (80,40), parent = mainLayout)
    mc.button("triangB", label = "Triangulate", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_03, command = triangulate)
    mc.button("fixMatB", label = "FixMaterial", width = 120, height = 40, backgroundColor = [0.2, 0.2, 0.2], parent = gridl_03, command = fixMaterial)
    ################################################################################################UI#################################################
    mc.showWindow()


###################################################################
##################                              ###################
##################    END OF SUPER BOOL TOOL    ###################
##################                              ###################
###################################################################
###################################################################
##################                              ###################
##################   BEGINNING OF MY UI SCRIPT  ###################
##################                              ###################
###################################################################

#### My custom script ####
def my_custom_script_com(*args):
    super_bool_ui()
    super_bool_tut()

# Create a custom floating window with 
if mc.window('ToolsWindow', q=True, exists=True):
    mc.deleteUI('ToolsWindow')
if mc.workspaceControl('ToolsWorkspaceControl', q=True, exists=True):
    mc.deleteUI('ToolsWorkspaceControl')
mc.window('ToolsWindow')
mainL = mc.columnLayout()
tabLayout = mc.tabLayout('ToolsTabs', p=mainL)

#########################################################
##################    IMPORTING PANEL    ################
#########################################################
tabMenu = mc.columnLayout("Menu", adj=True, p=tabLayout)
separator_long = mc.separator(
                         height=10,
                         style='in', p=tabMenu)

mc.button(label="MyCustomScript", command = my_custom_script_com, p=tabMenu)
mc.showWindow()
DrWeeny
  • 2,487
  • 1
  • 14
  • 17
  • Thank you very much for this, I think some changes weren't needed but I really appreciate you going through all of it! I'm going to try and use the superbool.py version of it so I don't have to have it live with my script, but we'll see :D I'll post back when I have tried! – PolyShifter May 16 '19 at 21:59