On Sat, Mar 18, 2017 at 5:15 AM Marcus Ottosson <[email protected]>
wrote:

> Thanks for sharing this Lidia!
>
> I had a closer look and found that you might not need shiboken2 nor the
> API to accomplish this.
>
> from PySide2 import QtWidgetsimport maya.cmds as cmds
>
> window = QtWidgets.QWidget()
> window.resize(500,500)
> qtLayout = QtWidgets.QVBoxLayout(window)
> qtLayout.setObjectName('viewportLayout')
> cmds.setParent('viewportLayout')
> cmds.modelPanel("embeddedModelPanel#", cam='persp')
> window.show()
>
> ​
>
>
Lidia's post was partially based on my older post
<http://justinfx.com/2011/11/20/mixing-pyqt4-widgets-and-maya-ui-objects/>
for pre-Maya 2017. And in my post I was using sip and the API to show how
to go back from the Maya cmds UI object to Qt again. Is that not needed
anymore? This shortened example doesn't include the second part where one
might be interested in accessing the modelPanel via Qt.

Also, I vaguely remember going the route of getting the full path to the
layout and using that to set it as the parent because of how the parent
hierarchy might have been set up. i.e. If the window was already parented
to the Maya main window, then its full path might be something like
"|MainWindow|MyWindow|MyLayout". So I was ensuring that a fully qualified
UI path was passed to setParent(). Not sure if this matters anymore, or if
its actually causing Lidia the unreliable behaviour since sometimes it
would work and sometimes not depending on the parented objects.

One thing I should have mentioned in my original blog post was the
importance of giving everything object names, since the Maya UI relies on
those for the full paths. And not setting any of those in between can
result in that strange naming of "|MainWindow|Widget|||Something" which
then can't be used in commands since it won't find the control.




> On 17 March 2017 at 15:57, Lidia Martinez <[email protected]> wrote:
>
>
> Hi folks,
>
> I published an article about embedding Maya's UI into PySide2 for Maya2017.
>
>
> http://blog.virtualmethodstudio.com/2017/03/embed-maya-native-ui-objects-in-pyside2/
>
> And again after the first fix I included, I had some errors running this
> code in a particular case. Maya was telling me '|' or '||' didn't exist.
>
> As you can see on the EDIT section (which is the second edit of the
> article), I wrote an explanation on how to fix this using
> setObjectName('layout') on the window and layout  which generates a better
> UI path:   window|layout|... instead of ||, and seems like Maya likes it
> better (I guess why).
>
> But then I found out I could even avoid getting the full name that just
> using setParent('layout')  would work without errors instead of using a
> path.
>
>
>
> I wanted to understand why this is working, even when I use the same
> object name with different windows. There's no name clash in Qt, and
> magically Maya's UI understands setParent anyway...
>
> Any idea why this is happening?
>
>
>
> --
> Lidia
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAAB1%3D8wqJ%3DBqpP06zQCtYqieqtYiOy62V90AcEps_bXD4WejXg%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAAB1%3D8wqJ%3DBqpP06zQCtYqieqtYiOy62V90AcEps_bXD4WejXg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> *Marcus Ottosson*
> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD2NeYiLExwsU5VfhCFDjjDGuOAjLSs_4yn0N-kFsqMPA%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD2NeYiLExwsU5VfhCFDjjDGuOAjLSs_4yn0N-kFsqMPA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2oksphQS3CUZN6FYWMJXGwu63xgz6aC0rDXWJHjm2Xrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to