Get Interface/Reference to Prim that Python Scripting Component Has been Applied To

I am working on developing a buoyancy plugin that will apply a buoyancy force to an object in IsaacSim. I found that I can add a Python Script to a certain Prim in the stage. I know there are ways to get access to a Prim in Python code at a certain path by specifically calling out that path.

I am curious if there is a way within the Python script to get the Prim that said Python script is attached to without explicitly specifying the path? It seems to me that this would be a very useful capability. The end goal is to have a single buoyancy.py script that can be applied to multiple Prims in the scene and apply a force based on the buoyancy equations. So I would want to get access to the Prim’s properties, density, mass, ability to apply body forces etc. Apologies if this is in the documentation somewhere, but I couldnt find a clear example of how to do this without hardcoding the path to the Prim of interest.

The solution was to create a Python Scripting Component that inherits from the BehaviorScript class. You can autogenerate this script by selecting "New Python Script (Behavior Script) when creating the new python script. This link shows visual examples on how to do that. Python Scripting Component - User Manual — Omniverse Extensions latest documentation (nvidia.com)

When this is setup behind the scenes in IsaacSim, the derived class then gets access to a variable “self.prim_path” which is the path of the prim that the script is attached to.

I do think there should be some more documentation on Python Scripting Components, with a simple code snippet example showing how to get access to the attributes of the prim the script is attached to.

I found some good code examples for how to use the BehaviorScript class in a livestream at the link below

Getting Started: Python Scripting Components | Omniverse Community Stream (youtube.com)

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