“How can I change the color of an existing light in an Omniverse stage?”
“How can I modify the color of an existing prim object in Omniverse?”
I wish to solve these tasks using the Python API. If possible, I’m curious about the sample code along with the libraries I need to import.
If you have experience solving this issue, please share it
import omni.usd
from pxr import Gf, Usd
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/CylinderLight")
attr = prim.GetAttribute("inputs:color")
attr.Set(Gf.Vec3d(0.8, 0.5, 0.5))
# Optionally you can provide time to animate color
attr.Set(Gf.Vec3d(0.8, 0.5, 0.5), Usd.TimeCode(2))
for prim in stage.Traverse():
prim_name = prim.GetName()
if “Sphere” in prim_name or “light” in prim_name:
print(prim_name)
xform = UsdGeom.Xform(prim)
print(xform.GetPath())
prim = stage.GetPrimAtPath(“/World/NUC12_07/Geometry/cart_12/Sphere/SphereLight”)
attr = prim.GetAttribute(“inputs:color”)
attr.Set(Gf.Vec3d(0.8, 0.5, 0.5))
Error in ‘pxrInternal_v0_20__pxrReserved__::UsdStage::_SetValueImpl’ at line 6028 in file C:\b\w\ca6c508eae419cf8\USD\pxr\usd\usd\stage.cpp : ‘Empty typeName for </World/NUC12_07/Geometry/cart_12/Sphere/SphereLight.inputs:color>’
I tried changing the color of the Light using the code you provided, but I encountered this error. It says there’s no attribute ‘.inputs:color’. Am I using it incorrectly?
and It would be helpful if you could also provide an API to reference which attributes are present in the prim object.