Problem of Using the Replicator with a fully developed scene

I did use the codes below to label a bear in existing loaded Issac sim scene but it seem not work.

import omni.replicator.core as rep
with rep.new_layer():
render_product = rep.create.render_product(‘/Root/Camera’, (2048, 1024))

def hide_bear():
    bear = rep.get.prims(path_pattern='/Root/Geometry/Bear')
    with bear:
        rep.modify.semantics([('class', 'bear')])
        rep.modify.visibility(rep.distribution.choice([True, False]))
    return bear.node

rep.randomizer.register(hide_bear)

# Setup randomization
with rep.trigger.on_frame(num_frames=100):
    rep.randomizer.hide_bear()

I do not know if that is the complete code, but your script is missing rep.orchestrator.run() in the end. Please post the complete code if possible.

I just want to find the prim and label it but the full code requires triggering randomization to both randomize and label.

Yes I understand that. I had a similar problem when I tried to retrieve the camera position. What you’re actually doing is preparing a graph - but that graph hasn’t run yet. I asume that’s why when you try to apply the labels that it is not working.

Hi @dangkhoa

I tried your script with a slight modification in Isaac.

import omni.replicator.core as rep

def hide_bear():
    bear = rep.get.prims(path_pattern='/World/BearCube')
    with bear:
        rep.modify.semantics([('class', 'bear')])
        rep.modify.visibility(rep.distribution.choice([True, False]))
    return bear.node

rep.randomizer.register(hide_bear)

# Setup randomization
with rep.trigger.on_frame(num_frames=100):
    rep.randomizer.hide_bear()

To simplify the scene added a cube instead of a bear called “BearCube”, but the script is functionally the same, aside from adding the replicator import at the top.

This script works correctly, but as julian mentioned above, when you enter this script into the script editor, you must click the “run selected” button at the bottom of the script editor to create the replicator graph. Then you can preview results by selecting Replicator>Preview a few times to verify that the bear is being randomly hidden or made visible.