I’m using the rep.randomizer.instantiate function to randomly choose a few object files from a specific folder, and I want to be able to access the file names for the specific files that it has chosen. The first print statement I use below returns the entire list of files that are in the folder, and the second simply returns the function I use to choose the files. Let me know if there are any suggestions on this. Thank you!
boxes = '/splost/all_models'
def get_random_object(size):
get_objects = rep.randomizer.instantiate(rep.utils.get_usd_files(boxes, recursive=True), size=size, mode='point_instance')
with get_objects:
print(rep.utils.get_usd_files(boxes)) #this prints all usd files that are in the all_models folder
print(get_objects) #this prints 'omni.replicator.core.randomizer.instantiate'
rep.randomizer.materials(mat_list)
rep.modify.pose(
position=rep.distribution.uniform((-200, -200, 200), (-200, -200, 200)),
rotation=rep.distribution.uniform((-90, -180, 0), (-90, 180, 0))
)
return get_objects.node
rep.randomizer.register(get_random_object)
Hi @michael.wood3 , now we don’t have a way to directly access in the code right not, but you can definitely access it in the writer. Here is an example:
import omni.replicator.core as rep
from omni.replicator.core import Writer, AnnotatorRegistry, BackendDispatch
cube = rep.create.cube(semantics=[("class", "cube")])
camera = rep.create.camera()
with rep.trigger.on_frame(num_frames=10):
with cube:
rep.modify.pose(
position=rep.distribution.log_uniform((0.1, 0.1, 0.1), (1, 1, 1), name="test_position")
)
render_product = rep.create.render_product(camera, resolution=(640, 480))
class CustomWriter(Writer):
def __init__(self, output_dir):
self._output_dir = output_dir
self._backend = BackendDispatch({"paths": {"out_dir": output_dir}})
self.annotators.append(AnnotatorRegistry.get_annotator("bounding_box_3d"))
def write(self, data):
print(data["distribution_outputs"])
print(data["bounding_box_3d"]["data"]["transform"])
rep.WriterRegistry.register(CustomWriter)
writer = rep.WriterRegistry.get("CustomWriter")
writer.initialize(
output_dir="./"
)
writer.attach([render_product])
data["distribution_outputs"]
will be a dictionary where its keys will be the names of the distribution nodes. In this case, it will contain test_position
and the values will be the distribution nodes’ values.
Hope this helps!