# Display buffer with format

This example shows an easy way to automate a repro case. It could be run as a command line argument when starting the UI, to avoid repetitive steps.

First the code opens a specified file, although this step could be omitted if the desired capture is already open.

    filename = "test.rdc"

    pyrenderdoc.LoadCapture(filename, filename, False, True)

Next we iterate through the list of buffers to find the one we want. The selection criteria are up to you, in this case we look at the name provided and identify the buffer by that, however it could also be a particular size, or the buffer bound at a given event.

    mybuf = renderdoc.ResourceId.Null()

    for buf in pyrenderdoc.GetBuffers():
        print("buf %s is %s" % (buf.resourceId, pyrenderdoc.GetResourceName(buf.resourceId)))

        # here put your actual selection criteria - i.e. look for a particular name
        if pyrenderdoc.GetResourceName(buf.resourceId) == "dataBuffer":
            mybuf = buf.resourceId
            break

    print("selected %s" % pyrenderdoc.GetResourceName(mybuf))

Once we’ve identified the buffer we want to view, we create a buffer viewer and display it on the main tool area.

    # Open a new buffer viewer for this buffer, with the given format
    bufview = pyrenderdoc.ViewBuffer(0, 0, mybuf, formatter)

    # Show the buffer viewer on the main tool area
    pyrenderdoc.AddDockWindow(bufview.Widget(), qrenderdoc.DockReference.MainToolArea, None)

## Example Source

`Download the example script`.

    filename = "test.rdc"
    formatter = "float3 pos; half norms[16]; uint flags;"

    pyrenderdoc.LoadCapture(filename, filename, False, True)

    mybuf = renderdoc.ResourceId.Null()

    for buf in pyrenderdoc.GetBuffers():
        print("buf %s is %s" % (buf.resourceId, pyrenderdoc.GetResourceName(buf.resourceId)))

        # here put your actual selection criteria - i.e. look for a particular name
        if pyrenderdoc.GetResourceName(buf.resourceId) == "dataBuffer":
            mybuf = buf.resourceId
            break

    print("selected %s" % pyrenderdoc.GetResourceName(mybuf))

    # Open a new buffer viewer for this buffer, with the given format
    bufview = pyrenderdoc.ViewBuffer(0, 0, mybuf, formatter)

    # Show the buffer viewer on the main tool area
    pyrenderdoc.AddDockWindow(bufview.Widget(), qrenderdoc.DockReference.MainToolArea, None)