Python Forum
Python says module doesn't exist... I say it does!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python says module doesn't exist... I say it does!
#1
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. :)

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 <maya console> 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:

"toolsMain.py"
import maya.cmds as mc
import userInterfaceElements as ELEM
reload (ELEM)

def toolsMain ():
	if (mc.window("toolsWindowMain", exists = True)):
		mc.deleteUI("toolsWindowMain")
	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")))
	
	mc.showWindow(toolsWindow)
"userInterfaceElements.py"
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)
"modelingTools.py"
def doMergeWindow ():
	print "POPPING UP A MERGE WINDOW NOW..."
Reply
#2
No enough info, so to start read up on the Python search path https://leemendelowitz.github.io/blog/ho...kages.html
Quote: Error: NameError: file <maya console> line 1: name 'MOD' is not defined #
Post the entire traceback for help, but this partial error message seems to say that in the file <maya console>, and you did not post the "maya console" program.
Reply
#3
Great. Thank you. I will read up!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  UndefinedEnvironmentName: 'extra' does not exist in evaluation environment EarthAndMoon 3 1,680 Oct-09-2023, 05:38 PM
Last Post: snippsat
  check if a file exist on the internet and get the size kucingkembar 6 1,758 Apr-16-2022, 05:09 PM
Last Post: kucingkembar
  SQLALCHEMY - Column doesn't exist jamesaarr 9 7,529 Nov-04-2021, 09:20 AM
Last Post: ndc85430
  keyboard module doesn't work in the microsoft version terminal of python. username 1 2,799 Feb-25-2021, 05:19 PM
Last Post: Larz60+
  why doesn't python look in two directions Kakha 21 6,454 Jan-01-2021, 11:24 PM
Last Post: jefsummers
  pathlib destpath.exists() true even file does not exist NaN 9 4,653 Dec-01-2020, 12:43 PM
Last Post: NaN
  Python IDE doesn't see opencv-python package on my Jetson Nano sadhaonnisa 1 3,332 Oct-11-2020, 01:04 AM
Last Post: Larz60+
  My Python Console doesn´t work ModuleNotFoundError: No module named 'tokenize' RuanKishibe 1 3,125 Aug-06-2020, 10:07 PM
Last Post: deanhystad
  Syntax not exist noorpy 1 1,998 Nov-14-2019, 09:23 AM
Last Post: perfringo
  Shutil attempts to copy directories that don't exist ConsoleGeek 5 4,523 Oct-29-2019, 09:26 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020