Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 2.59 KB

File metadata and controls

87 lines (63 loc) · 2.59 KB

HowTo: quickpreview

Preview

Original MaxScript Tutorial Source Code

Goals:

  • learn to record preview frames of an animation

Explanations

  • Define an AVI output path name in the Previews system directory.
  • Get the size of the current viewport.
  • Create a bitmap with the size of the viewport and set the file name to the output path .
  • Loop through all animation frames in the current segment.
  • Set the slider to the time from the loop.
  • Capture the viewport Device Independent Bitmap.
  • Copy the DIB to the pre-defined bitmap.
  • Save the current frame to disk.
  • When ready with all frames, close the bitmap.
  • Force garbage collection manually to clear any used memory.
  • Load the ready animation in the RAM player.

Using the tool

From the 3ds Max listener window we can do:

import quickpreview

quickpreview.startup()

If we install this sample as a pip package it will be automatically started during the startup of 3ds Max (because it defines a startup entry point for 3ds Max).

Understanding the code

We use rt.getDir(rt.Name("preview")) to find the default directory for previews (3ds Max System Directories). We concatenate "quickpreview.avi" using the standard Python path.join function.

    preview_name = path.join(rt.getDir(rt.Name("preview")), "quickpreview.avi")

We then retrieve the view size, and create a bitmap that matches this size in the preview_name file:

    view_size = rt.getViewSize()
    anim_bmp = rt.bitmap(view_size.x, view_size.y, filename=preview_name)

We then iterate over the animationRange, creating a bitmap from the viewport at each frame. This bitmap is copied to the anim_bmp that we created and then saved.

    for t in range(int(rt.animationRange.start), int(rt.animationRange.end)):
        rt.sliderTime = t
        dib = rt.gw.getViewportDib()
        rt.copy(dib, anim_bmp)
        rt.save(anim_bmp)

After the loop is over we close the anim_bmp file that now contains our animation.

    rt.close(anim_bmp) 

We then force a garbage collection:

    rt.gc()

And launch the RAMPlayer for our generated avi:

    rt.ramplayer(preview_name, "")