Can I pm.playblast from within mayabatch? - python

I am trying to playblast multiple Maya scenes in a folder, without bringing up the Maya GUI.
I have successfully invoked a headless Maya instance with mayabatch.exe
That instance calls a script that crawls a folder
Each scene is opened
But I cannot playblast the scene file
1. Purple noise
If I simply call pm.playblast(format='movie', filename=some_filepathname, viewer=False, forceOverwrite=True, offScreen=True) I get an AVI file with purple noise. If I switch to format='image' I get a sequence of images with purple noise.
2. Cannot lookThru
Based on some sample playblast code, I tried calling pm.lookThru("persp") first, but this triggers the following traceback:
# File "C:\Users\username\Documents\playbatch\blaster.py", line 23, in blast_file
# pm.lookThru("persp")
# File "C:\Program Files\Autodesk\Maya2016\Python\lib\site-packages\pymel\inte
rnal\pmcmds.py", line 133, in wrappedCmd
# res = new_cmd(*new_args, **new_kwargs)
# RuntimeError: There is no active view.
...presumably because a headless instance has no view.
3. Forcing a single renderable camera has no effect
A relatively recent (2015) post TO [Maya-Python], "Playblasting in standalone" suggests that all that is needed is a single renderable camera.
cams = cmds.ls(type='camera')
for cam in cams:
cmds.setAttr(cam + '.rnd', 0)
cmds.setAttr('persp.rnd', 1)
...but this still renders purple noise.
Calling the playblast command from the Maya Script Editor / GUI works. Is it possible to playblast from a headless/mayabatch instance? If so, what other values need to be set for a successful playblast?

You can't blast with mayabatch as it uses the GUI.
You have two options :
Render with hardware renderer
Open a maya and execute playblast

Actually you can do playblasts in mayabatch or mayapy mode (The two having different background by default in playblasts). I never went very deeply into it but I had similar results than with a classic Maya playblast. I don't think you have access to HUD options and other graphical settings and there can be problems if you have hardware shaders or other non-standards shaders to display.
Never use "look through", just set your cameras as renderable cameras with that script you linked, Maya will do the rest.
Don't use pymel either, it can bring very sneaky bugs and I wouldn't be surprised if it didn't work in batch mode. Try not to even import its module as it sets a lot of things in the background (I encountered some weird behaviour and bugs in batch mode while it was working in interactive mode).
Are your purple playblasts done with an already custom made Maya scene or did you create a very basic file first with like primitives and nothing fancy? Get a good result with a basic setup, then once you have a good result try with your real scenes. If it doesn't work with them then try to reduce it to find what's wrong in it. Or implement, step by step, things from your final scenes to your basic working scene to find what is doing that.
Otherwise you can launch Maya without GUI with the environment variable MAYA_OVERRIDE_UI. Set it to a mel filename located in a script folder and you can then launch Maya with a simpler window with a bit of mel.
You can also get help from the maya-capture library so that you don't have to code everything yourself.
Use Hardware Renderer.

Related

VTK Render Mouse Interaction (Python)

I want to visualize one or more STL file(s) using a vtk render viewport inside my application. I was able to get it all running with this example here: https://kitware.github.io/vtk-examples/site/Python/IO/ReadSTL/
My question is as follows: I have a mouse to control it and it is just unbelievable how bad default the controls of the camera are. It is almost impossible to get the model rotated intentionally or focus on a certain part. I am confused as I could not find any topic here or elsewhere discussing this. Normally I would read through other threads to find an answer, but there doesn't seem to be any. So, maybe you can point me to an approach or even certain functions of how I can change these settings, that would be really great! Basically I want to mimic the camera behavior of say, Paraview or a common CAD tool. Like zooming with mouse wheel, rotating with RMB and holding down the wheel to pan.
Some background on my project: I have written a python program and created a quite ok UI using tkinter. However, recently I was thinking of rewriting some basic parts of it and also upgrading everything visually and in terms of handling. So, I want to move to Qt widgets and, there shall be a VTK rendering viewport inside my application to show some of the stuff that can be interacted with.
I was able to find a solution in the tutorials. By explicitly defining the vtkInteractorStyle with
style = vtk.vtkInteractorStyleTrackballCamera()
The handling is just as I wanted it to be.

Keep track of which files are created by a certain process

I'm using a Python (3.3) script to run a command that will render a whole bunch of image files for an animation film.
While it's rendering, it creates an empty image file every time it starts a new frame of the animation, and when it's done rendering that frame, it saves the image over that empty file and moves onto the next frame.
The python script starts this rendering process by running another script using:
proc = subprocess.Popen(cmd, shell=True)
Is it at all possible to check which files were created during this process?
The reason being, someone may wish to stop the render before it finishes, but when they do so there will be an empty image file left over. I'd like to have the script delete the empty images when the big red Stop Render button is pushed, but I cannot simply delete all empty images because there may be other computers rendering - the empty images are there to prevent multiple computers rendering the same frame (they skip that frame if the image file for it exists).
If it helps, all the computers use Windows 7, and the animation program that does the rendering is Maya (2014).
If there's no easy way, I'd be happy to use any kind of ugly hack to get the job done :)
If you are doing this in Maya, you can use mayapy interpeter that comes with Maya (rather than mayaBatch or maya -r). Inside of standalone you can run any script(s) you need to setup the render, execute it, and post-process the results. At a minimum, that will let you handle one frame at a time and use python to submit the images one at a time.
A basic setup would be:
Create a python script that does what you need to do and works correctly inside the maya python interpeter. The script will be run as if it were in the maya listener, so you can import maya.cmds and use maya features as needed.
If the script needs command line arguments, use sys.argv to retrieve them. When you run the script, any arguments you pass in will be available in sys.argv.
Your script can get access to all of Maya's functionality by importing maya.standalone and calling it's initialize method (more details here)
From the command line, run the mayapy.exe that lives in the bin folder of your maya install. The -s flag allows you to specify a script to run, so you'll pass in the python script as an argument, followed by any other arguments you need: something like "path/to/mayapy.exe" -s "path/to/yourscript.py" arg1 arg2 arg3.
You won't be able to catch a user cancelling via control-c but you could request cancellation from outside using a TCP connection to the maya command port, or even just by prompting for user input after each frame
For a fancier operation you can run an rpc server inside your Maya using something like ZeroMQ or RpyC. You could also make your own with a WSGI server listening to the http port.
You can also look in to 3d party render management systems. There are some open-source ones here

Python, transparent window with a red outine of a rectangle

Hi I am new to this whole coding thing I was suggested to use Python. The version I have now is 2.7. I need help with making a transparent window to the copacity of 100 so that you can actually see through it and I also want to know how to make a fairy thick, out line of a rectangle in the colour red.
Help me please :S Thanks!
Unfortunatelly, there is not such an easy thing as sa "trasnparent window" - althougmodern widnow managaers do have various opacity controls for the windows, those just affect the windows as a whole - and do not integrate at all with the program running "inside" the windows. There may even be, for some of them, a way to call functions to explicitly set up the opacity level of a given window, but I don't think it willbe possible for all of them.
That said, it is possible to get grab of the "root" window and draw directly on the screen - -bypassing the window manager. There are APIs for that at least on Windows and Linux (you have to mention in what operating system you need that working) - but it will amount to not a trivial research work, since this is not what is expected of a "well behaved app" - for which the GUI toolkits are written and documented. You will need to write xlib code in Linux, and directly call win32 api's on windows - both are possible from Python - as possible as under-documented.
And once you get to draw the rectangle, since you are bypassing the window manager, you willhave to care about every low-level detail of your app: mouse event handling, screen-redrawing (and notifying the system of drawing taking effect over other windows), and so on.

Globally poll which files are being dragged in Windows API?

I'm wondering if it's possible to globally poll which (if any) files are currently being dragged in Windows using the Windows API, independently of any particular window.
For example, I'm doing some stuff with networking where, when the user drags a file to the edge of the screen, it notifies a separate computer that the file has hit the screen edge. I've got my program running in the background, but it's not windowed, and it's hard (impossible) to place my window around all 4 screen edges.
I'm doing this in Python, but if I have to use another language and write a wrapper around it that's fine too.
You want to hook DoDragDrop.

Which display manager for a non interactive Python app and mplayer?

I am developing an application that will run on Linux to run fullscreen all the time (no menus or trays or anything will be visible).
The application is going to be developed in Python, not that that matters as far as the window manager, but what I am having a hard time with is choosing a window manager.
I need something with the smallest possible footprint, that will let me run a graphical Python app and have an mplayer window at the same time, at widescreen resolutions (widescreen, 16:10,16:9, etc). Other than that, it doesn't need a lot of features, but the end footprint size is the most important thing I'll be looking at.
What window manager would you recommend?
EDIT: There won't be any interaction with the application needed.
You don't actually need any window manager or display manager. All you need to do is open your initial window with the same geometry as the root window. I suppose you could even draw directly into the root window if you wanted.
If you are using some display library it probably has an easy way to open a full screen window. For example using a recent enough version of SDL through pygame you can do
pygame.display.init()
surface = pygame.display.set_mode((0,0),pygame.FULLSCREEN,0)
to get a window that fills the entire screen. This will work even if there is no window manager running.
As for mplayer, it accepts the -geometry flag, so you can use something like mplayer -geometry 640x480+20+20 to display the mplayer window 20 pixels from the top 20 pixels from the left and with a size of 640x480 pixels.
You probably meant window manager. Display manages are KDM, GDM and the like. Windoe managers, to name, GNOME, Xfce, KDE, ratpoison, fvwm, twm, blackbox are a few. ratpoison gives full screen to the application that is in the foreground but demands heavy keyboard interaction (hence the name ratpoison) and no mouse interaction at all.
I assume you'll be running both your python GUI and mplayer in some sort of geometries combination that shows both at the same time, filling the screen.
As commented, you should not need a window manager to achieve that. You could have your python GUI app get command-line parameters for setting its window geometry and also call fullscreen mplayer with the -geometry parameter. That should fill the screen as expected, without any window decorations.
Now you could have the startx script called for the user running it all and have a custom ~/.xinitrc script doing something like:
#!/bin/sh
exec python my_gui_app --whatever-sets-geom &
exec mplayer -fs video.avi
If yout pyhon app will instead be launching mplayer then just leave the first 'exex' call (remove the '&') and have it call mplayer as desired with the expected dimensions in '-fs' mode.
Please note you may need to use something like the 'xset' program to disable monitor blanking due to energy savings, hide the cursor (although IIRC that's something mplayer does for its own window), and things like that.
Also, somethimes running, for example, GTK apps on a bare X display may end up using an "ugly" theme, so you may need to have the toolkit style configuration taken care of someway.
I am doing something similar on my "set-top box" and I don't use any window manager.
It boots debian, and from inittab I auto-login the user that runs the display. That user's .profile starts X, which runs .xinitrc, which starts my python app that runs as a network server in front of mplayer (running mplayer in -slave mode).
My python app does not have a GUI element - only mplayer runs on the X display. But in your case, it should be no different. As I mentioned in a comment to another answer, you may want to look into how you can reparent mplayer's window to give you greater control over its placement and/or movement/size.
Doing it this way avoided a display manager and a window manager. This simplifies the solution, boots faster and uses a smaller footprint (it runs of an SD card, with heaps of room to spare).
I realize this is an old question, but I use openbox on my system, I have created a custom config file that disables all mouse keyboard shortcuts, and removes borders etc on the applications.
In the openbox config i even created some secret shortcuts that can run fx. an xterm for debugging live on the box.
The openbox documentation was very helpful in figuring everything out, I did the config in about 30 minutes.

Categories

Resources