LumaPictures / pymel

Python in Maya Done Right
Other
490 stars 131 forks source link

shorthand operations #214

Open pmolodo opened 9 years ago

pmolodo commented 9 years ago

From chad...@gmail.com on April 10, 2010 12:57:10

i think i've finally pieced together a set of attribute operators that i'm satisfied with adding to pymel

we got rid of our overload of setattr because we did not have a similar shorthand for getting the value of an attribute. i stumbled across a blog ( http://xeash.net/?p=22#respond ) that suggests an operator that i was not aware of: the unary negation operator '~'

null1.tx = 5 # set attribute to 5 a = ~null1.tx # assign value to variable null2.tx = ~null1.tx # set attribute to value of another attribute

i greatly prefer this over another suggestion made in Issue 86 .

also, we should add an isConnected operator:

null1.tx >> null2.tx null1.tx >>= null2.tx # true

it could of course work in the reverse direction. direction (source to destination) matters!

null1.tx <<= null2.tx # false

i really like shorthand syntax for messing around in the script editor or in ipymel, but i don't like using it in modules because it is more difficult to read as one must be familiar with pymel idioms.
i would prefer if there were a way that this mode had to be enabled per module as with the 'with' statement, so that each module had to add a statement like the following:

from pymel.core import shorthand

however, without overriding the import command i don't think we could get the callbacks we need for per-module control. is there another way to control this that does not globally enable the mode for all modules?

Original issue: http://code.google.com/p/pymel/issues/detail?id=179

pmolodo commented 9 years ago

From gXe...@gmail.com on April 25, 2010 03:53:01

Chad, im glad my suggestion in blog was helpful(sorry site now is down for a while), too bad you didn't reply me about this on github though(i sent a message there to you cause of oliver suggestion). about shorthand module. why do this hard way? what is needed to do is just add ability to write short and long syntax anywhere(even mixed) and this will be up to user which one to use. this way you can write modules using long syntax and use shorthand in script editor. another reason im a against importing separate module for shorthand syntax is it will be over-complicated for user. just imagine : each time you want to play with shorthand you need to import shorthand module. plus i don't think this module would be so expensive for loading so its no point in doing it separately.