Replicatorwrapper got error message

I use the code below to modify the object pose in the Isaac sim stage, and got error message:

>>> rep.modify.pose(position=(1,0,0), input_prims=["/Replicator/Sphere_Xform"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ar_admin/.local/share/ov/pkg/isaac_sim-2022.1.1/exts/omni.replicator.core-1.4.3+lx64.r.cp37/omni/replicator/core/scripts/utils/utils.py", line 295, in __call__
    return ReplicatorItem(self.__fn, *args, **kwargs)
  File "/home/ar_admin/.local/share/ov/pkg/isaac_sim-2022.1.1/exts/omni.replicator.core-1.4.3+lx64.r.cp37/omni/replicator/core/scripts/utils/utils.py", line 312, in __init__
    self.node = self.__fn(*args, **kwargs)
  File "/home/ar_admin/.local/share/ov/pkg/isaac_sim-2022.1.1/exts/omni.replicator.core-1.4.3+lx64.r.cp37/omni/replicator/core/scripts/modify.py", line 113, in pose
    _position(position, input_prims)
  File "/home/ar_admin/.local/share/ov/pkg/isaac_sim-2022.1.1/exts/omni.replicator.core-1.4.3+lx64.r.cp37/omni/replicator/core/scripts/utils/utils.py", line 295, in __call__
    return ReplicatorItem(self.__fn, *args, **kwargs)
  File "/home/ar_admin/.local/share/ov/pkg/isaac_sim-2022.1.1/exts/omni.replicator.core-1.4.3+lx64.r.cp37/omni/replicator/core/scripts/utils/utils.py", line 312, in __init__
    self.node = self.__fn(*args, **kwargs)
  File "/home/ar_admin/.local/share/ov/pkg/isaac_sim-2022.1.1/exts/omni.replicator.core-1.4.3+lx64.r.cp37/omni/replicator/core/scripts/modify.py", line 333, in _position
    return node
UnboundLocalError: local variable 'node' referenced before assignment

local variable 'node' referenced before assignment

The reason is that in the omni/replicator/core/scripts/modify.py ==> def _position() if the input_prims is given, the code will turn into the 2rd branch, which the node is not defined!

@ReplicatorWrapper
def _position(position: ReplicatorItem, input_prims: Union[ReplicatorItem, List[str]] = None) -> og.Node:
    """Modify the position of the prims specified in `input_prims`.

    Args:
        position: XYZ coordinates in world space.
        input_prims: The prims to be modified. If using `with` syntax, this argument can be omitted.

    Example:
        >>> import omni.replicator.core as rep
        >>> cube = rep.create.cube()
        >>> with cube:
        ...     rep.modify._position(rep.distribution.uniform((0, 0, 0), (100, 100, 100)))
        omni.replicator.core.modify._position
    """
    if isinstance(position, ReplicatorItem):
        node = create_node(
            "omni.replicator.core.OgnWritePrimAttribute", attribute="xformOp:translate", attributeType="double3"
        )
        utils._setup_random_attribute(write_node=node, attribute_value=position, prim_path=input_prims)
    elif input_prims:
        _set_position(input_prims, position)
    else:
        # Still creating a distr node because we don't want to dynamically set the resolved type.
        distr_node = uniform(position, position)
        node = create_node(
            "omni.replicator.core.OgnWritePrimAttribute", attribute="xformOp:translate", attributeType="double3"
        )
        utils._setup_random_attribute(write_node=node, attribute_value=distr_node, prim_path=input_prims)

    return node

I followed the API documentation: API — omni_replicator 1.6.4 documentation

ps. The position do changed after i run the code, that means it really works, but the code given in replicator definitely have problems.

Hi there, can you write the steps/script you are running which causes you this issue? Thanks!

Hi @baikaixin , were you able to resolve the issue?, if not then please provide the steps/script to help you find the solution.

just add a sphere in isaac sim and then use the command above the modify the position, then we could get the error.

Can you provide the location you are running the command from (e.g, script editor, standalone app etc.)?

@baikaixin, can you provide a response as requested in earlier message to understand the issue and help you provide the solution.

If the issue is resolved then please update the comment and mark it “Closed”.

This does not seem to be an issue on newer versions, the following snippet works as intended:

import omni.replicator.core as rep

rep.create.sphere()
rep.modify.pose(position=(1, 1, 1), input_prims=["/Replicator/Sphere_Xform"])

I am using version isaac_sim-2022.1.1. Which newer version are you referring to?

2022.2.1? at least that’s the newest release available from the Launcher.

yes, 2022.2.1

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.