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 09-28-2012, 04:00 AM   #1
EightBit
Lord of the posts
Mitch Rosefelt
OutThereSumwhere, USA
 
Join Date: Jan 2008
Posts: 1,044
Problem Testing Selected Python defs in Eclipse

When I try to execute selected code that includes a function, it won't
register the function.

I have this code in a module ( _ = space):
def process_all_textures():
_print ('Process all textures.')
_process_all_textures()
_print type(process_all_textures)

def junk():

_print ('junk')
_junk()
_print type(junk)


If I run the code in PyDev (Run As Python Run, Ctrl+F11), it executes
correctly.

If I select any of the text and send to Maya, it executes correctly,
(after the def has been registered).

However, when I select the first 4 lines of text and execute those
lines only in PyDev (Crtl+Alt+Enter - which is Interactive Console), I
get this error:
File "<console>", line 3
process_all_textures()
^
SyntaxError: invalid syntax
print type(process_all_textures)
<type 'function'>

Ctrl+Alt+Enter with no text selected executes the whole module correctly.

Anyone have insight?
Thanks.
__________________
If animation couldn't change the world, it wouldn't be such a Micky-Mouse place.

Last edited by EightBit : 09-28-2012 at 04:05 AM.
 
Old 09-28-2012, 02:40 PM   #2
djx
Where's my pony?
 
djx's Avatar
David Johnson
vfx & creature td
Melbourne, Australia
 
Join Date: Jun 2003
Posts: 3,362
Ok, this is what I think you may have done...

First you ran the code like you wrote it here (ie all indented ) so you function was recursive, with no limit. ie it calls itself within itself, but the interpreter simply registered the function.
Then you noticed the indentation mistake and fixed it, moving process_all_textures() out of the function definition,

Code:
def process_all_textures(): print 'process all textures' process_all_textures() print type(process_all_textures)

and you ran all 4 lines again. It should have worked, but the interpreter has cached the original defintion of the function so it still errors.

Try deleting the orginal definition by doing this first
del(process_all_textures)

David
__________________
http://www.djx.com.au
 
Old 10-05-2012, 09:56 PM   #3
EightBit
Lord of the posts
Mitch Rosefelt
OutThereSumwhere, USA
 
Join Date: Jan 2008
Posts: 1,044
Thanks for the reply as always David:
I didn't run the function call inside the function - I just showed the wrong indentation when I added the underscores above (this is a great CG forum, but I WISH they would install a good python formatting option).
However, after a bunch more time troubleshooting, I discovered that when sending a selection to the interpreter, the selection must include at least one empty line (no tabs) below the function. Else it won't register correctly and execution as well as 'del()' will fail. Note also if not selected correctly the new definition will corrupt a previously registered function of the same name, causing the error shown above.

Glad that is solved.
The del function is good to know.
__________________
If animation couldn't change the world, it wouldn't be such a Micky-Mouse place.
 
Old 10-05-2012, 09:56 PM   #4
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 05:20 AM.


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