[pymel][ui]

EDIT: Sorry for bad thread name, forgot to finish it :slight_smile:

I’m having weird problem with one of my scripts, its working on some machines and on some is not.
On some machines it worked in past, but stopped working.
Its basic thumbnailing tool, that makes another viewport inside script window.

cam = modelPanel(getPanel(wf=True), q=True, cam=True)
select(cam)
cam = ls(sl=1)[0]

normalFov = cam.getFocalLength()
cam.setFocalLength(120)
w = window("Make thumbnail", width = 250,height=250)
form = formLayout()
editor = modelEditor()
print editor
t = text("Setup viewport for thumbnail")
b1 = button("Make thumbnail", width=90)
b2 = button("Nothing", width=90)

formLayout( form, edit=True, 
attachForm=[(t, 'top', 15), (t, 'left', 30), (t, 'right', 30), (editor, 'top', 30), (editor, 'left', 30),(editor, 'bottom', 30),(editor, 'right', 30),(b1, 'bottom', 3), (b1, 'left', 30),(b2, 'bottom', 3), (b2, 'left', 130) ])

modelEditor(editor, e=1, dtx=1, nurbsCurves=1, nurbsSurfaces=1, cameras=1, joints=0, wos=0, deformers=0, locators=0, lights=1, textures=1, handles=0, grid=0, ikHandles=0, hud=0, dimensions=1, displayAppearance="smoothShaded", vs=0, sel=True)
modelEditor(editor, edit=True, camera="perspShape" )
		
showWindow( w )

Error comes in at line modelEditor(editor, e=1, dtx=1… and reads:
‘Make_thumbnail|formLayout168|modelEditor1’ not found. #

Any ideas what could cause such inconsistency with this script?

a. use namespaces, it is a lot less confusing than importing everything into main.
b. write cleaner code.

now you problem, since you say it dosnt always happen i think it is related to your usage of the getPanel(wf=True) call since that relies on having the right part of the UI with focus.

Could you explain what your trying to do, and i can see if i can come-up with a solution to the problem.

if i understand you correctly something like this is what you want.


import pymel.core as pm

class UI(object):
    def __init__(self):
        if pm.window('thumbnail', exists=True):
            pm.deleteUI('thumbnail')

        with pm.window('thumbnail', width=256, height=256) as win:
            with pm.paneLayout():
                cam = pm.PyNode('persp')
                normalFov = cam.getFocalLength()
                cam.setFocalLength(120)

                panel = pm.modelPanel()
                editor = panel.getModelEditor()
                pm.modelEditor(editor, e=True, dtx=1, nurbsCurves=1, nurbsSurfaces=1,
                               cameras=1, joints=0, wos=0, deformers=0, locators=0,
                               lights=1, textures=1, handles=0, grid=0, ikHandles=0,
                               hud=0, dimensions=1, displayAppearance="smoothShaded",
                               vs=0, sel=True, camera='perspShape')
        win.show()

UI()

If you explain what it actually has to do, i can come up with better.

@passerby, thanks for help.

Main thing that was problematic was direct use of modelEditor.
My code:

editor = modelEditor()

Your code:

panel = modelPanel()
editor = panel.getModelEditor()

Your example works always, but you get shelf at top of viewport available (view,shading,lighting,…) , which isn’t really a problem, just to note.

As for namespaces, i usually import pymel directly, everything else using namespace, I don’t know why I started doing this, but I’m sticking to it for now.
As for cleaner code, this is pretty old app that I’m fixing, newer code is better, but still could use a lot of improvements. For this example I copied everything from classes and functions just to demonstrate problem in best way, which didn’t go as planned :slight_smile:

ya when I was testing it seems the model editor can only exist within a panel which is why I did that.

I think this might be your problem:

cam = modelPanel([B]getPanel(wf=True)[/B], q=True, cam=True)

You are querying for a camera in a currently focused panel which can be any number of panels Maya’s gui has including the ones that are not model panels.
That might explain inconsistent behaviour you’re noticing. Try having a model panel selected when you launch your tool and see how it behaves.
It would probably be better to remove that dependency from your code.