Execute Function everytime a new scene gets generated by Replicator

Hello,
I have a very simple question, but couldn’t figure out for myself, since I am not very good at coding tbh.
Is there a possibility to execute a defined function every time the replicator generates a new scene/after taking the pictures. I want to read out the bounding box of my bin and do other stuff, but when I just write it like this it won’t work. The bounding box will only get read out at the beginning of my code execution, but not every time the scene gets generated new. Same if I put the code sniplet in my “bin_place” rep. function.

def bbox_bin():
    cache = create_bbox_cache()
    bin_prim_path = "/Replicator/Ref_Xform"
    bbox = compute_aabb(cache,bin_prim_path,include_children=True)
    print(bbox)

with rep.trigger.on_time(interval= 8, num=2):
    rep.randomizer.bin_place()
    rep.randomizer.env_props(10)
    rep.randomizer.sphere_lights(10)
    rep.randomizer.material_edit()
    bbox_bin()

Replicator has a built in bbox writer.

You can set it up like so based on your code provided:

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))

    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize( output_dir="_output", rgb=True,   bounding_box_2d_tight=True)
    writer.attach([render_product])

    with rep.trigger.on_time(interval= 8, num=2):
        rep.randomizer.bin_place()
        rep.randomizer.env_props(10)
        rep.randomizer.sphere_lights(10)
        rep.randomizer.material_edit()

Hello Jen, yes I also use this for my writer, but I need to use the coordinates of my bounding box to drop parts only inbetween my corners, since I want to simulate a bin-picking scenario with parts falling into a bin and delete parts outside before taking the images. Since I change the rotation and position of my bin slightly with every iteration I can’t use global coordinates, that’s why I want to use the bbox of my object every iteration.

Currently, replicator does not support adding relative locations using omnigraph for moving targets. E.g. randomizing the location of objects relative to another object. As I understood, this is something you wanted to achieve.

You can, however, use Isaac Sim / USD API for this. You can use rep.orhecstrator.step() to manually generate the randomizations and after each step you can read out the location and bounding boxes of your assets, and move them around.

Here are some examples of using orchestrator.step() and of spwaning/reading bounding box values in isaac sim.