How to use omni.replicator.core.modify.register API?

As title,
I want to keep regenerating the number and position of cube groups in each trigger, I think the omni.replicator.core.modify.register API can solve my problem, but I’m not sure how to use it, I used it in that way, but I got an error.
Or if there have any others API is more suitable for me, feel free to tell me!


    with rep.trigger.on_frame(num_frames=3, interval=200):
        group = create_cube_group(random.randint(10,19), random.randint(1,3))
        with group:
                 create_cube_group(random.randint(10,19), random.randint(1,3)), override=True

Error: AttributeError: __ enter __

Hello @lily.chen,

Replicator register() functions allow you to extend Replicator modules with your own custom functionality. This is most often desired when desiging your own Omniverse Extension as a way to extend Replicator capabilities and meet the needs of your unique project and application.

To register and use a custom function, the following pattern is used:

# Define custom functionality
# Note: function must return a node or a ReplicatorItem object
def create_cube_group(number_of_cubes):
    cubes = rep.create.cube(count=number_of_cubes):
    with cubes:
        rep.modify.pose(position=rep.distribution.uniform((0, 0, 0), (100, 100, 100)))
    return cube

# Register with replicator

# Now, `create_cube_group` is accessible through the `rep.randomizer` module
with rep.trigger.on_frame(num_frames=3, interval=200):

I am asking about rep.modify.register not rep.randomizer.register

The answer is the same, it just changes the namespace where the method is registered. It can be under randomizer/modify/distribution

@ christianbarcelo
Could you please give me the example for how to use rep.modify.register for whatever scenario? Many thanks

Sorry for the delay here.
AFAIK, the only thing that changes is the name of the module your method is register into.
You can either do:

def my_fancy_distribution():
  distribution = rep.distribution.combine(rep.distribution.uniform(...), rep.distribution.normal(...))
  return distribution.node


def my_fancy_modification():
  xform = rep.get.xform(path_pattern=...)
  with xform:
  return xform.node


def my_fancy_randomization():
  xform = rep.get.xform(path_pattern=...)
  with xform:
  return xform.node

It’s all the same, the methods are just wrapped as ReplicatorItems inside the module you select, but they will all work the same, you can register under one module or another with no difference at all.