View Full Version : Importing defs from external py files

03 March 2011, 05:32 PM
Hey everyone,

In order to tidy up a script i'm currently working on, i'm trying to put some of my defs into external py files in the documents/maya/scripts directory and impor them into the script editor. So for example, I have a file called which contains a def called checkStreetAccess(), and i'm importing it into the main script editor with 'import checkStreetAccess' followed by 'print checkStreetAccess.checkStreetAccess(). However, I then get the following error:

# Error: NameError: file C:/Users/Ben-i7/Documents/maya/scripts\ line 3: global name 'cmds' is not defined #

I have 'import maya.cmds as cmds' at the top of the external py files, as well as in the main script editor. Could anybody point out where i'm going wrong?



03 March 2011, 08:06 PM
Your module is called getNeighbors
Your definition is called checkStreetAccess()

You need to import the module:
import getNeighbors

and then call the method using the scope of the module:

It doesn't sound like you are doing this in your example? You may be confusing different files?

03 March 2011, 12:08 PM
Sorry, ignore The file is

03 March 2011, 04:33 AM
Post the whole script and ill take a look.
You could try just:
import maya

then use maya.cmds.<command>

Are you within maya python tab when executing this?

03 March 2011, 12:03 PM
Thanks for your help - I figured it out, just need to add a reload( checkRoadAccess ) to update all the changes I made!

Cheers, Ben

CGTalk Moderation
03 March 2011, 12:03 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.