-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSetScale.py
More file actions
40 lines (33 loc) · 1.18 KB
/
SetScale.py
File metadata and controls
40 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pxr import Usd, UsdGeom, UsdPhysics, UsdShade, Sdf, Gf, Tf
import omni.usd
import omni.timeline
# Get stage.
stage = omni.usd.get_context().get_stage()
# Get selection.
selection = omni.usd.get_context().get_selection()
paths = selection.get_selected_prim_paths()
# --------------------------------------------------.
# Set scale.
# --------------------------------------------------.
def _setScale(prim : Usd.Prim, sV : Gf.Vec3f):
if prim == None:
return
scale = prim.GetAttribute("xformOp:scale").Get()
if scale != None:
# Specify a value for each type.
if type(scale) == Gf.Vec3f:
prim.GetAttribute("xformOp:scale").Set(Gf.Vec3f(sV))
elif type(scale) == Gf.Vec3d:
prim.GetAttribute("xformOp:scale").Set(Gf.Vec3d(sV))
else:
# xformOpOrder is also updated.
xformAPI = UsdGeom.XformCommonAPI(prim)
xformAPI.SetScale(Gf.Vec3f(sV))
# --------------------------------------------------.
for path in paths:
prim = stage.GetPrimAtPath(path)
if prim.IsValid() == True:
# Print prim name.
print(f"[ {prim.GetName()} ]")
sV = Gf.Vec3f(1.1, 1.2, 1.3)
_setScale(prim, sV)