maya python time code

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 07 July 2013   #1
maya python time code

here is a block of code i dont understand..
####
import maya.cmds

maya.cmds.playbackOptions( minTime='1sec', maxTime='3sec' )

startFrame = maya.cmds.playbackOptions(query = True, minTime = True)
####

i dont understand how the "1sec" is setting the minTime in the maya timeline
in theory

"1sec" is a string and there for a variable that contains numerical value.

so if i write
###
print 1sec
###
it should give me the value

but instead i get an error..
# Error: invalid syntax
# File "<maya console>", line 6
# print 1sec
# ^
# SyntaxError: invalid syntax #


also, how come minTime is also able to function as a boolean as in "minTime = True"

I had trouble finding anything in the maya/help files that defines what the argument time really is. Is it safe to assume that it returns both a numerical value and a boolean value?

i know it imported python module, but maybe someone can explain how 1sec gets its value?
__________________
CALIBER STUDIO

Last edited by cooperunionstud : 07 July 2013 at 01:07 AM.
 
Old 07 July 2013   #2
I think you're getting a little confused by the syntax used when calling Maya commands through Python, and also the different states of Maya commands (create, edit and query).

maya.cmds.playbackOptions( minTime='1sec', maxTime='3sec' )

This is a command in create mode and the argument type is "time" (not float or string, although it can be either). When you pass in a string of the correct format (e.g. '1sec') internally Maya knows how to handle it (multiplying it by the fps to get the frame). If you pass in a numeric value Maya will treat it as a frame.

For example, '1sec' at 24 fps will return frame 24. '3sec' at 30fps will return frame 90.
Quote: also, how come minTime is also able to function as a boolean as in "minTime = True"
startFrame = maya.cmds.playbackOptions(query = True, minTime = True)

Because the query flag is set, this command is in query mode, querying the minTime value. Short answer, it's for Python syntax reasons that you need to pass the boolean value. This is to indicate which parameter to query (unlike MEL where you can just set the flag itself).

Keep in mind, Python is a dynamic language, unlike MEL (or C or Java), variables can be of any type and can even change throughout the program. When passed to a function, it is up to that function to handle the different variable types (that it may expect). This is why minTime can be a float, a (properly formatted) string, or a boolean.

Quote: i know it imported python module, but maybe someone can explain how 1sec gets its value?

The playbackOptions function gives it meaning.

-ChrisZ
 
Old 07 July 2013   #3
thank you for your help, i think in understand it better now, one other question i have is, i have seen python script editor in maya with the ability to auto complete code. or as some would call it, enable script completion by showing a drop down menu with possible codes. this is done by hitting the ctrl and space key in osx, for some reasons it doesnt work in windows.. is there a way around it? or are the keys different in windows for this feature?
thanks in advance.
__________________
CALIBER STUDIO
 
Old 07 July 2013   #4
Auto-completion on Windows uses the same hotkey (Ctrl+Space). Make sure that you have Command Completion enabled in the Script Editor (under the command menu).

Keep in mind, there are a number of limitations with Maya's native script editor auto-completion. Most notably, it only lists built-ins and elements that exist in the main (Python) namespace. Things have to be imported (or executed) first. So, for example, if you've never executed the code that imports module x, it will not auto-complete. It also won't list local variables, methods, etc... in the current buffer code.

-ChrisZ
 
Old 07 July 2013   #5
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



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 04:48 PM.


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