CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-01-2011, 05:32 PM   #1
beentheunseen
New Member
portfolio
Ben Minton
Nottingham, United Kingdom
 
Join Date: Mar 2011
Posts: 12
Thumbs up Importing defs from external py files

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 getNeighbors.py 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\checkStreetAccess.py 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?

Thanks!

Ben
 
Old 03-01-2011, 08:06 PM   #2
dbsmith
Frequenter
Damon Smith
Technical Artist
Sidhe
Wellington, New Zealand
 
Join Date: Oct 2005
Posts: 253
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:
getNeighbors.checkStreetAccesss()

It doesn't sound like you are doing this in your example? You may be confusing different files?
 
Old 03-02-2011, 12:08 PM   #3
beentheunseen
New Member
portfolio
Ben Minton
Nottingham, United Kingdom
 
Join Date: Mar 2011
Posts: 12
Sorry, ignore getNeighbors.py... The file is checkStreetAccesss.py
 
Old 03-03-2011, 04:33 AM   #4
dbsmith
Frequenter
Damon Smith
Technical Artist
Sidhe
Wellington, New Zealand
 
Join Date: Oct 2005
Posts: 253
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?
 
Old 03-08-2011, 12:03 PM   #5
beentheunseen
New Member
portfolio
Ben Minton
Nottingham, United Kingdom
 
Join Date: Mar 2011
Posts: 12
Thanks for your help - I figured it out, just need to add a reload( checkRoadAccess ) to update all the changes I made!

Cheers, Ben
 
Old 03-08-2011, 12:03 PM   #6
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:14 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.