Connection is not captured in the first run

21 views
Skip to first unread message

yann19

unread,
Jun 19, 2019, 8:43:28 PM6/19/19
to Python Programming for Autodesk Maya
I am trying to query for the default expression used in the imagePlane with the following code:

# Part01
img = cmds.imagePlane()
frame_ext_attr = "{0}.useFrameExtension".format(img[0])
cmds.setAttr(frame_ext_attr, True)

# Part02
print '>>> ', cmds.listConnections("{0}.frameExtension".format(img[0]))

If I am running the above code block as a whole, the return result in `Part02` is `None`.
However, if I run them in 2 parts, `Part02` will then be returning me `['expression1']` as the result.

Why are there 2 different results?

I have tried using some mel-based commands such as `refreshAE` or `updateAE <node path>`, in hope that the (whole) code block will be able to capture the expression in the first run, but it is not.

Any ideas?

r...@colorbleed.nl

unread,
Jun 26, 2019, 6:51:26 AM6/26/19
to Python Programming for Autodesk Maya
It's likely that since this creates the expression on an attribute change that only in the next "idle" state or upon a certain event post-process the expression gets added by Maya.

Unfortunately I've found no way to actually make this process correctly. Here's some things I quickly tried:


(Somehow I'm not getting the WYSIWYG editor, so I'm not sure code formatting will work)

[CODE]

import maya.mel
from PySide2 import QtWidgets
import time

# Part01
img = cmds.imagePlane()
frame_ext_attr = "{0}.useFrameExtension".format(img[0])
cmds.setAttr(frame_ext_attr, True)

# Force update? (tests)
for x in range(2):
# Run twice so "any order" of commands after each other
# is run and tested.
QtWidgets.QApplication.instance().processEvents()
cmds.refresh(force=True)
maya.utils.processIdleEvents()
maya.mel.eval("refreshAE;")
maya.mel.eval("updateMainWindowComponentState();")
time.sleep(0.05)

# Part02
print '>>> ', cmds.listConnections("{0}.frameExtension".format(img[1]))
[/CODE]
Reply all
Reply to author
Forward
0 new messages