The RenderSettings class includes methods that allow you to set all common render settings, such as: the height and width of your render, your output file, pre/post render scripts, and so forth. These settings correspond directly to settings found on the Common tab in the Render Scene Dialog.
The RenderExecute class includes the QuickRender method that allows you to execute your render.
The ViewportManager class allows you to iterate through the viewports and perform tasks such as maximize the viewport, set a viewport as active, zoom out of the viewport, and so forth. See Working with the viewport below for more information.
To execute your render, use RenderExecute.QuickRender():
To set an output file to which your render is saved, use the RenderSettings.SetOutputFile() and RenderSettings.SetSaveFile() methods as follows:
render = MaxPlus.RenderSettings render.SetOutputFile(MaxPlus.PathManager.GetTempDir() + r"\testRender.jpg") render.SetSaveFile(True)
To set the width and height of your render, use the RenderSettings.SetWidth() and RenderSettings.SetHeight() methods as follows:
render.SetWidth(640) render.SetHeight(480)
You can also set up pre and post render scripts as follows:
render.SetPreScriptFile(MaxPlus.PathManager.GetScriptsDir() + r"\Your_preRender_Script.ms") render.SetPostScriptFile(MaxPlus.PathManager.GetScriptsDir() + r"\Your_postRender_Script.ms") render.SetUsePreScript(True) render.SetLocalPreScript(True) render.SetUsePostScript(True)
You can also set other global options such as: whether or not to perform render effects, whether to render atmospheric effects, whether to render hidden objects and so forth. For example, you can choose to render hidden objects using the following:
render.SetHidden(1)
The example demoRender.py defines a ViewType class that is a dictionary with entries for all the available view types, and lists the numerical values for each view type and its corresponding string representation.
Viewport.GetViewType() obtains the view type for the viewport.
To zoom out to view all geometry in all viewports, use the method: ViewportManager.ViewportZoomExtents().
To maximize a viewport, use ViewportManager.SetViewportMax(True).
Enumerate across ViewportManager.Viewports to access each of the viewports.
Note: ViewportManager.Viewports is a generator and not a list or tuple; therefore, you cannot call len(ViewportManager.Viewports).
The example demoRender.py iterates through each of the viewports, and prints out the view type for each viewport in the workspace (in both numerical and string representation formats).
for view in MaxPlus.ViewportManager.Viewports: viewType = view.GetViewType() print "%d - %s - %s (%d)" % (index, MaxPlus.ViewportManager.getViewportLabel(index), ViewType.GetKey(viewType), viewType)
Note: It calls the previously defined ViewType.GetKey() method to obtain the string representation for the view type.
It then finds the first viewport with a perspective view and sets it as the active viewport, and maximizes it.
It then sets the output file, enables saving and renders the scene.
render.SetOutputFile( outputPath ) render.SetSaveFile( True ) MaxPlus.RenderExecute.QuickRender()
For information on how to create a bitmap, see Creating a bitmap.
After you have created a bitmap as follows, you can follow the directions below to render a range of frames and write the bitmap to an image file.
import MaxPlus # Create a bitmap rendbm = MaxPlus.Factory.CreateBitmap() # First allocate some storage. This is where the type of bitmap is determined. BMM_TRUE_64 = 7 storage = MaxPlus.Factory.CreateStorage(BMM_TRUE_64) # Now we can get the bitmap info info = storage.GetBitmapInfo() # Set some common properties on the bitmap info.SetWidth(640) info.SetHeight(480) # Allocate storage for writing to the bitmap storage.Allocate(info, 2) # Set the storage on the bitmap rendbm.SetStorage(storage) # Set the bitmap output base file name info.SetName(MaxPlus.PathManager.GetRenderOutputDir() + r'\FramesRender.tga') print info.GetName() # Display the bitmap rendbm.Display()
Call ViewportManager.GetActiveViewport() to get the active viewport, then pass it as a parameter to RenderExecute.Open(). RenderExecute.Open() performs all the setup on the renderer instance that is required before rendering a set of frames.
view = MaxPlus.ViewportManager.GetActiveViewport() MaxPlus.RenderExecute.Open(view, MaxPlus.RendType.Normal, rendbm.GetWidth(), rendbm.GetHeight())
Call Bitmap.OpenOutput() to prepare the bitmap for writing to the image file.
rendbm.OpenOutput(info)
To render a range of frames, set up a for loop, and call RenderExecute.RenderFrame() and pass the Bitmap and (frame number * 160) as the input parameters. You must multiply the frame number by 160 because each frame contains 160 ticks.
Call Bitmap.Write() to write the bitmap to the image file. The second argument is converted to a string and appended to the bitmap output base file name; for example, if the base file name is FramesRender.tga, and the frame is 20, then the image file name will be: FramesRender0020.tga.
for frame in range(0, 100, 20): MaxPlus.RenderExecute.RenderFrame(rendbm, frame*160) rendbm.Write(info, frame)
Call RenderExecute.CloseCurrent() to close the renderer instance and free the memory allocated during RenderExecute.Open().
Call Bitmap.Close() to tell the bitmap that it has completed writing to the image file.
MaxPlus.RenderExecute.CloseCurrent() rendbm.Close(info)
Your render results are displayed in the Rendered Frame Window, and in addition, they are saved to the location you specified when calling BitmapInfo.SetName(). In this example, 5 frames are rendered (0, 20, 40, 60, 80, as determined by the for loop), and each output file name has its frame number attached (for example FramesRender0020.tga).