Python says module doesn't exist... I say it does!


Hello all!

I am much newer to scripting in Python and my experience is almost exclusively limited to writing tools for use in a Maya production pipeline for which I am the exclusive author. So please excuse the rudimentary nature of the code! I am learning best practices as I go. :slight_smile:

Here is my issue: I have a “toolsMain” script which I use to call functions from a “userInterfaceElements” script for UI element creation. From there, the commands on the buttons and widgets will call functions from a “modelingTools” script which I import as “MOD”. When I run the scripts in Maya, the UI loads correctly, but when I press the “Merge” button on the UI window I get the following error: # Error: NameError: file line 1: name ‘MOD’ is not defined #

But I know it does. I have quadruple checked my spelling and syntax multiple times, and I am beginning to think something is happening that I don’t quite understand and haven’t seen before. I have successfully imported scripts, passed arguments between scripts and functions in the past, but this seems new and different and I can’t quite figure it out. Any help would be greatly appreciated!!! Thanks in advance!

The code for the 3 scripts is below in its simplest form for cut and paste purposes:

import maya.cmds as mc
import userInterfaceElements as ELEM
reload (ELEM)

def toolsMain ():
if (mc.window(“toolsWindowMain”, exists = True)):
toolsWindow = mc.window(title=“Tools Window”, iconName= “toolsWindow”, widthHeight=(400, 500))
scrollMain = mc.scrollLayout(“ScrollLayoutMain_01”, w=390, hst=16, vst=16)
tabsMain = mc.tabLayout(“TabLayoutMain_01”, imw=5, imh=5)

##TAB 1 - Main
tab_1 = ELEM.stdColumnLayout(“ColumnLayout_01”, “TabLayoutMain_01”)

## Modeling Frame ##
ELEM.stdFrameLayout("ModelingFrame_01", "ColumnLayout_01", "Modeling")
ELEM.stdRowColumnLayout("ModelingRowColumn_01", "ModelingFrame_01")
#Modeling Buttons
ELEM.modelingButton("MergeButton_01", "Merge", "merge", "MOD.doMergeWindow()")
#Organize Tabs
mc.tabLayout(tabsMain, edit=True, tabLabel=((tab_1, "Main")))


import maya.cmds as mc
import modelingTools as MOD
reload (MOD)

def stdColumnLayout(name, daddy): #(name, parent)
mc.columnLayout(name, parent=daddy, rowSpacing=5, columnWidth=390)
return name

def stdFrameLayout(name, daddy, callIt): #(name, parent, label)
mc.frameLayout(name, parent=daddy, label=callIt, borderVisible=True, collapsable=True, width=390)

def stdRowColumnLayout(name, daddy): #(name, parent)
mc.rowColumnLayout(name, parent=daddy, numberOfColumns=3, rowSpacing=[10, 5])

def modelingButton(name, callIt, tip, runIt): #(name, label, annotation, command)
toolTip = “DEFAULT”
mc.button(name, parent=“ModelingRowColumn_01”, label=callIt, annotation=toolTip, command=runIt, enableBackground=True, backgroundColor=[0.68, 0.76, 0.66], width=125, height=30)

def doMergeWindow ():


when you pass the string “MOD.doMergeWindow()” into the mc.button() command, it is just a string. When you press the button, maya evaluates the string as if it is a stand alone script file. As such, it doesn’t know anything about the MOD module you declared in You will need to pass in the string “import modelingTools as MOD; MOD.doMergeWindow()”