Writer Examples

Within replicator there are multiple off-the-shelf writers. Below are a few examples of the usage of included writers applied on a scene using Replicator APIs.

Learning Objectives

Through this page you will see some highlighted writers and how to use them. However, for all randomizers available and more information consult the API documentation .

Set up

Each of the writers shown below are standalone scripts that can be run following the set up described in Setting up the Script Editor and Running and Previewing Replicator.

Basic Writer

The basic writer is used in many examples, but for the sake of completeness, here is a simple example script showing its use. In the following code, the default Writer is initialized and is attached to the renderer to produce the output of the images and annotations with 2D bounding boxes. Note the user can specify a specific output directory for the writer to use.

writer = rep.WriterRegistry.get("OmniWriter")

writer.initialize(run_id=1, output_dir="_output", rgb=True,   bounding_box_2d_tight=True)


Below is the entire script which can be copied directly to the script editor.

import omni.replicator.core as rep

with rep.new_layer():

    camera = rep.create.camera(position=(0, 0, 1000))

    render_product = rep.create.render_product(camera, (1024, 1024))

    torus = rep.create.torus(semantics=[('class', 'torus')] , position=(0, -200 , 100))

    sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(0, 100, 100))

    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(100, -200 , 100) )

    with rep.trigger.on_frame(num_frames=10):
        with rep.create.group([torus, sphere, cube]):
                position=rep.distribution.uniform((-100, -100, -100), (200, 200, 200)),
                scale=rep.distribution.uniform(0.1, 2))

    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")

    writer.initialize( output_dir="_output", rgb=True,   bounding_box_2d_tight=True)



Kitty Writer

Example of usage of the Kitty writer, that writes Kitty format data. Below is the entire script which can be copied directly to the script editor.

import omni.replicator.core as rep

sequential_pos = [(0, 100, 500),(500, 100, 500),(-500, 100, 500),]

with rep.new_layer():
    cube = rep.create.cube(position=(200, 0, 0), semantics=[('class', 'cube')])
    sphere = rep.create.sphere(position=(0, 0, 0), semantics=[('class', 'sphere')])
    cone = rep.create.cone(position=(-200, 0, 0), semantics=[('class', 'cone')])

    camera = rep.create.camera(position=sequential_pos[0], look_at=(0,0,0))

    with rep.trigger.on_frame(num_frames=3):
        with camera:
            rep.modify.pose(look_at=(0,0,0), position=rep.distribution.sequence(sequential_pos))

# Will render 512x512 images
render_product = rep.create.render_product(camera, (512, 512))

# Get a Kitti Writer and initialize its defaults
writer = rep.WriterRegistry.get("KittiWriter")
# Attach render_product to the writer

# Run the simulation graph