api.OpenMaya.MDGContext error 2020

Skip to first unread message

juan c

Jul 28, 2021, 6:17:52 PMJul 28
to Python Programming for Autodesk Maya
i am trying to get some value at time:

from maya.api import OpenMaya
time = OpenMaya.MTime(20)
context = OpenMaya.MDGContext(time)
node_obj = OpenMaya.MSelectionList().add('persp').getDependNode(0)
node = OpenMaya.MFnDependencyNode(node_obj)
plug = node.findPlug('tx', False)
value = plug.asMDistance(context)

this freezes maya for a second or two and spits out this error:

# sys:1: DeprecationWarning: Call MPlug::asType() instead. If needed, use MDGContextGuard switch context.

it works fine on older maya versions, and using the old api.

any ideas?

vince touache

Jul 28, 2021, 9:23:48 PMJul 28
to Python Programming for Autodesk Maya
super weird, it seems to work fine on 2022, meaning it might not be an actual deprecation warning. Any chance you can try it with a newer version of maya ?

juan c

Aug 1, 2021, 6:21:45 PMAug 1
to Python Programming for Autodesk Maya
i have only got 2020 unfortunately. api version 20200405.
i suppose it's good news that it's not happening on 2022, but i would be curious to get some ideas on why it's failing here.
i am resorting to checking maya version and setting the context as current, in case it's 2020... which is less than ideal.
thanks for checking!
Reply all
Reply to author
0 new messages