There are seldom areas where scripts' speeds actually impact the job
you are doing.
Yes, there are things I can do to really slow down my scripts (lots
and lots of prints statements perhaps?), but if our scripts are
working efficiently, they will be using Maya to do the heavy lifting,
not the scripting.
Something that PyMEL has helped us accomplish, and has helped with a
specific known speed issue, is the ability to pass a selection as an
mObject, rather than converting it to a string, passing the string and
then converting back to an mObject. (kind of like the lots and lots of
prints statements above, only applied to how commands communicate
their results to the next command) This can be really important when
the names of the selections need to be really long because there are
many levels of hierarchy and the objects have been duplicated many
times.
Also, as suggested, taking advantage of python enabled API queries is
fast and safe, and PyMEL has built this into normal scripting
situations. You don't have to do anything special to take advantage
of this other than use PyMEL, API opportunities are built in. (and
it's a great place to look to see how it's done, in case you'd like to
work out how to make things faster in this way)
Along the lines of passing strings into commands...
The example is doing just that:
pm.setAttr("locator1.tx",5)
whereas, if you built the locator in your script, assigining it to a
variable, and then set that attr using the variable, then you should
avoid needing to convert the string to the mObject.
myL = pm.spaceLocator()
pm.setAttr(myL.tz,5)
Also, perhaps you are also seeing the time it takes to do the first
part in the example:
import pymel.core as pm
It takes a little time to import pymel. It's doing a lot. It should
not be factored into performance tests.
This part is done once in Maya(like starting Maya), and could be put
into your userSetup.py to make it more invisible.
If you use PyMEL, you don't tend to use it as a one-off here and
there, you tend to work with it to accomplish a major task, or in a
series of inter-working tools. The more you use it, the more
opportunities it has to save you time at runtime, as well as during
development.
-JohnCreson
On Sun, Oct 3, 2010 at 3:58 AM, Paul Molodowitch <[email protected]> wrote:
> Yes, Ofer is basically right, in that pymel's priority has always been ease
> of use over execution speed. If execution speed is your thing, then pymel
> probably isn't the right tool for the job.
> Having said that, though, I would like to take a look at what can be done to
> try to speed up pymel at some point...
> - Paul
>
> On Sat, Oct 2, 2010 at 10:49 PM, Count Zer0 <[email protected]> wrote:
>>
>> Well put Ofer.
>>
>> IMHO, the speed of coding in PyMEL FAR outweighs the lack of speed in
>> script execution. 99% of the time, script execution speed is near
>> instantaneous, so PyMEL is the proper thing to use.
>>
>> When you get into lots of mesh iteration and weights stuff, you might
>> want to go back to maya.cmds or better yet get into Python API calls.
>> I think that stuff works even faster then MEL or maya.cmds, not as
>> fast as compiled API, of course.
>>
>> Chad confirms this at the bottom of this thread:
>> http://forums.cgsociety.org/archive/index.php/t-833446.html
>>
>> -jason
>>
>> On Oct 2, 7:36 pm, Ofer Koren <[email protected]> wrote:
>> > pymel is more about the speed of coding, less about the speed of the
>> > code... right Paul?
>> >
>> > - Oferwww.mrbroken.com
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Sat, Oct 2, 2010 at 1:22 PM, Paul Molodowitch <[email protected]>
>> > wrote:
>> > > (err... that should have read 'area', not 'are'...)
>> > > - Paul
>> >
>> > > On Sat, Oct 2, 2010 at 1:21 PM, Paul Molodowitch <[email protected]>
>> > > wrote:
>> >
>> > >> For setAttr, it doesn't create a pynode... but the command is
>> > >> wrapped, so
>> > >> it will still be slower than the maya.cmds equivalent.
>> > >> In general, though, speed is one are where PyMel still has a lot of
>> > >> room
>> > >> for improvement...
>> > >> - Paul
>> > >> On Sat, Oct 2, 2010 at 12:29 PM, breeder <[email protected]>
>> > >> wrote:
>> >
>> > >>> Example:
>> > >>> import pymel.core as pm
>> > >>> pm.setAttr("locator1.tx",5)
>> >
>> > >>> So , in this example , does pymel use maya.cmds or is actually
>> > >>> creating PyNode for "locator1" and than setting attribute???
>> >
>> > >>> On Oct 2, 8:16 pm, Jo Jürgens <[email protected]> wrote:
>> > >>> > A node in maya.cmds is just a text string, while in Python it is a
>> > >>> > PyNode
>> > >>> > instance. Creating all those instances in PyMel does take time.
>> > >>> > For
>> > >>> > operations on large number of items where speed is crucial, I
>> > >>> > still
>> > >>> > tend to
>> > >>> > use maya.cmds.
>> >
>> > >>> --
>> > >>>http://groups.google.com/group/python_inside_maya
>> >
>> > > --
>> > >http://groups.google.com/group/python_inside_maya
>>
>> --
>> http://groups.google.com/group/python_inside_maya
>
> --
> http://groups.google.com/group/python_inside_maya
--
http://groups.google.com/group/python_inside_maya