Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[omtk2] Node Editor - Convert pymel logic to OpenMaya2 #31

Open
renaudll opened this issue Jan 6, 2018 · 0 comments
Open

[omtk2] Node Editor - Convert pymel logic to OpenMaya2 #31

renaudll opened this issue Jan 6, 2018 · 0 comments
Labels

Comments

@renaudll
Copy link
Owner

renaudll commented Jan 6, 2018

Current (pymel) implementation is really slow when doing connection traversal.
I've done some quick benchmarks and OpenMaya2 seem the faster for this.

# Benchmark cmds vs OpenMaya vs OpenMaya2
# For each attr of each nodes, get the name of each connected attrs
import time
import pymel.core as pymel
from maya import OpenMaya
from maya.api import OpenMaya as om2

all_ = []
objs = pymel.ls()
print("Scanning {0} nodes".format(len(objs)))
st = time.time()
for obj in objs:
    for attr in obj.listAttr():
        all_.append(attr.name())
et = time.time()

print("Pymel took: {0}".format(et-st))

###

# Benchmark cmds vs OpenMaya vs OpenMaya2
# For each attr of each nodes, get the name of each connected attrs
import time

all_ = []
mfns = [obj.__apimfn__() for obj in pymel.ls()]
print("Scanning {0} nodes".format(len(mfns)))
st = time.time()
for mfn in mfns:
    for i in xrange(mfn.attributeCount()):
        a = mfn.attribute(i)
        amfn = OpenMaya.MFnAttribute(a)
        all_.append(amfn.name())
et = time.time()

print("OpenMaya took: {0}".format(et-st))

###

pymel.select(pymel.ls())
sel = om2.MGlobal.getActiveSelectionList()
all_ = []
print("Scanning {0} nodes".format(sel.length()))
st = time.time()
for i in xrange(sel.length()):
    mfn = om2.MFnDependencyNode(sel.getDependNode(i))
    for j in xrange(mfn.attributeCount()):
        a = mfn.attribute(j)
        amfn = om2.MFnAttribute(a)
        all_.append(amfn.name)
et = time.time()
print("OpenMaya2 took: {0}".format(et-st))

Result in:

Scanning 286 nodes
Pymel took: 6.77531504631
Scanning 286 nodes
OpenMaya took: 0.150294065475
Scanning 280 nodes
OpenMaya2 took: 0.108594894409
@renaudll renaudll changed the title Node Editor - Convert pymel logic to OpenMaya2 [omtk2] Node Editor - Convert pymel logic to OpenMaya2 Mar 20, 2019
@renaudll renaudll added the omtk2 label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant