Adding thumbnails in pyside mobu


#1

Hey,
I’m converting a script from maya to motionbuilder. And noticed thumbnails not showing up in motionbuilder…? Is there some trick to getting thumbs working in motionbuilder?

Here is an excerpt from what i’m trying to do:
icon = QtGui.QIcon(“path.jpg”)
newItem = QtGui.QListWidgetItem(‘test’)
newItem.setIcon(icon)
list.addItem(newItem)

which works in Maya, but shows nothing in mobu?


#2

hmm… I’ve just quickly checked how I add icons in Mobu. I use this combination:
item = QListWidgetItem(“name”)
icon = QPixmap(‘D:\icon_file.png’)
item.setIcon(icon)

But I don’t remember why excactly :wink:


#3

I just figured it out, thanks for the hint. Mobu only likes png… i tried jpg and tifs lol… Do you have a way to save png’s directly in mobu?


#4

No, I didn’t try yet. In FBImage doc I saw only option to save as tif.
This would probably need solution based on python or qt. I mean save to tif, then convert it by some python function. Maybe external lib would be needed.


#5

The pillow library can be used to convert images from one format to another.

I believe the QImage class should be capable of writing out a PNG file as well, but that requires QImage to load the image from whatever other format, which may or may not be supported depending on how Qt was built for Mobu.
I don’t have it installed so can’t really test myself.


#6

heh, yeah, QImage is supported in mobu 2017 and there is option to open tif and save as png, but my first try failed. It return False when I load tif. need to do more research.


#7

This way seems to work: ( Saving the tif then loading back in a converting to png with pixmap. I’ve also tested the resulting png works in pyside.

Save tif
image = FBVideoGrabber().RenderSnapshot(700, 400, False, False, False, True, True, True, True)
image.WriteToTif("{}fBImage.tif".format(path), “”, True)
Convert to png
pixmap = QtGui.QPixmap("{}fBImage.tif".format(path))
filename = “{}fbImage.png”.format(path)
pixmap.save(filename, ‘png’)
Delete tif
os.remove("{}fBImage.tif".format(path))

( It takes about double the time having to save then load and convert, but its still pretty quick )


#8

Just a heads up, @mobo you can wrap code in ``` ``` (those are backticks, usually shares a key with ~) for better formatting:

# Save tif
image = FBVideoGrabber().RenderSnapshot(700, 400, False, False, False, True, True, True, True)
image.WriteToTif("{}fBImage.tif".format(path), “”, True)
# Convert to png
pixmap = QtGui.QPixmap("{}fBImage.tif".format(path))
filename = “{}fbImage.png”.format(path)
pixmap.save(filename, ‘png’)
# Delete tif
os.remove("{}fBImage.tif".format(path))

#9

Great! thanks for the heads up, good to know.


#10

Ha, after getting that to work i’m running 2015 at work and seems QImage reader doesn’t support tif.
this the printout from 2015:

[PySide.QtCore.QByteArray(‘bmp’), PySide.QtCore.QByteArray(‘pbm’), PySide.QtCore.QByteArray(‘pgm’), PySide.QtCore.QByteArray(‘png’), PySide.QtCore.QByteArray(‘ppm’), PySide.QtCore.QByteArray(‘xbm’), PySide.QtCore.QByteArray(‘xpm’)]


#11

Ha new development. So I looked at the option of upgrading to 2019 as a way to avoid this issue…
However I downloaded the trial of mobu 2019. And WriteToTif is not working ( doesn’t seem to do anything in 2019. But in 2018 / 15 works )

FBSystem().Scene.Evaluate()
FBimage = FBVideoGrabber().RenderSnapshot(400, 200, False, False, False, True, True, True, True)
FBimage.WriteToTif("{}{}.tif".format(path, 'test'), "", True)

The FBimage is created but does not output to tif. Although it does print True.


#12

hmm I had some luck grabbing window with pyside instead. eg. pixmap = QtGui.QPixmap.grabWindow(widget.winId()). Where widget is the viewer widget in the motionbuilder interface. However a lot of the time this failed and instead only got me a white screen. If I instead grab the desktop with the same setup it seems to always work, but I’m not grabbing the whole desktop which is not ideal…


#13

hehe, we think similar :wink: I also tried this. But I don’t need this currently so I gave up.
The best I manage was this grabing of desktop with additionally cropping it to Viewer coordinates.
This works fine but it’s a bit slow (with my 2 monitors setup it’s 1-2s), and is hacky.

globalPos = Viewer.mapToGlobal(QPoint(0, 0))
widgetRect = Viewer.geometry()
widgetRect.moveTopLeft(globalPos )
QPixmap.grabWindow(QApplication.desktop().winId(),widgetRect.x(),widgetRect.y(),widgetRect.width(), widgetRect.height()).save('D:\\screenshot.png', 'png')

Grabbing Viewer widget gave me only blank background without models and even Grid. What is interesting, Skeleton parts were captured on the screenshot. Maybe XRay mode in viewport allowed it.
For grabing widget I used QPixmap.grabWidget() function
For what I read, grabing desktop works in different way than grabing praticular windows or widgets. Maybe some additional vieport refresh is needed…

BTW. did you tried to render one frame ? I mean using File->Render option, but from python and as output choosing only one current frame and JPG format. (but probably jpg is not perfect here because it won’t be displayed by QPixmap…)


#14

Ha, yeah exactly the same path i ended up down lol. I also have my windows taskbar on the side which made the viewer position offset :(.
I briefly looked at the render a frame route, but 2015 mobu QImage reader does not support that either… could try bmp… I also tried to some things to refresh the viewport for Qimage grab, but nothing worked so far.

Currently I am grabbing the desktop then opening that in a new widget with a crop tool to select the area u want. Not ideal, but works for now.

Thanks


#15

Never really dug into the crash dump files themselves.

Usually I just go on a logging spree, and pick through Maya’s log on the off chance that I’ll get some good information.

Though I’ve found that the majority of cases where Maya hard crashes is either from a janky plugin, or a threading problem. Minus the cases where Maya is just being unstable all on its own.