Python Error, Custom Prim Data

Hi together,

I want to extract the location of the i_points and save it inside the “Custom Prim Data” of the fabrik_system prim could anybody help me where the issue could be?


from omni.kit.scripting import BehaviorScript
from pxr import Usd, UsdGeom, Gf
import omni.usd

class FabrikBehavior(BehaviorScript):
   def on_init(self):
       self.stage = omni.usd.get_context().get_stage()

   def on_play(self):
       try:
           i_points_path = "/World/Scripts/fabrik_system/i_points"
           i_points = self.stage.GetPrimAtPath(i_points_path)
           
           positions = []
           # Sort points by index number
           i_points_list = []
           for child in i_points.GetChildren():
               name = child.GetName()
               if name.startswith('i_'):
                   idx = int(name[2:])  # Get index number
                   i_points_list.append((idx, child))

           # Process points in sorted order
           for _, point in sorted(i_points_list):
               xform = UsdGeom.Xformable(point)
               matrix = xform.ComputeLocalToWorldTransform(Usd.TimeCode.Default())
               pos = matrix.ExtractTranslation()
               positions.append([float(pos[0]), float(pos[1]), float(pos[2])])

           # Save to fabrik system
           fabrik_prim = self.stage.GetPrimAtPath("/World/Scripts/fabrik_system")
           if fabrik_prim:
               fabrik_prim.SetCustomDataByKey('fabrikData', {
                   'num_points': len(positions),
                   'point_positions': positions
               })

       except Exception as e:
           print(f"Error: {e}")

   def on_stop(self):
       fabrik_prim = self.stage.GetPrimAtPath("/World/Scripts/fabrik_system")
       if fabrik_prim:
           fabrik_prim.SetCustomDataByKey('fabrikData', {})

Error_message.txt (4.2 KB)

regards YuuZena

ValueError: invalid literal for int() with base 10: ‘points’

This error indicates that the script attempts to convert the string ‘points’ into an integer, which is not feasible. It appears that there is at least one child primitive named ‘i_points’, which is causing the error.