Skip to content

Commit 33a0270

Browse files
marktuckerpixar-oss
authored andcommitted
Adding python bindings for VtArray<SdfPathExpression> objects.
Without these additions, it is not possible to use python to get or set attributes or metadata of type Sdf.ValueTypeNames.PathExpressionArray. (Internal change: 2358305)
1 parent 0380d05 commit 33a0270

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

pxr/usd/sdf/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pxr_library(sdf
131131
module.cpp
132132
wrapArrayAssetPath.cpp
133133
wrapArrayPath.cpp
134+
wrapArrayPathExpression.cpp
134135
wrapArrayTimeCode.cpp
135136
wrapAssetPath.cpp
136137
wrapAttributeSpec.cpp
@@ -193,6 +194,7 @@ pxr_test_scripts(
193194
testenv/testSdfPath2.py
194195
testenv/testSdfPath2Construct.py
195196
testenv/testSdfPathExpression.py
197+
testenv/testSdfPathExpressionArray.py
196198
testenv/testSdfPayload.py
197199
testenv/testSdfPrim.py
198200
testenv/testSdfReference.py
@@ -469,6 +471,11 @@ pxr_register_test(testSdfPathExpression_Cpp
469471
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfPathExpression_Cpp"
470472
)
471473

474+
pxr_register_test(testSdfPathExpressionArray
475+
PYTHON
476+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfPathExpressionArray"
477+
)
478+
472479
pxr_register_test(testSdfParsing
473480
PYTHON
474481
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfParsing"

pxr/usd/sdf/module.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TF_WRAP_MODULE
1414
{
1515
TF_WRAP( ArrayAssetPath );
1616
TF_WRAP( ArrayPath );
17+
TF_WRAP( ArrayPathExpression );
1718
TF_WRAP( ArrayTimeCode );
1819
TF_WRAP( AssetPath );
1920
TF_WRAP( ChangeBlock );
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/pxrpythonsubst
2+
#
3+
# Copyright 2025 Pixar
4+
#
5+
# Licensed under the terms set forth in the LICENSE.txt file available at
6+
# https://openusd.org/license.
7+
8+
from pxr import Sdf, Tf
9+
import sys, unittest
10+
11+
MatchEval = Sdf._MakeBasicMatchEval
12+
13+
class TestSdfPathExpressionArray(unittest.TestCase):
14+
15+
def test_Basics(self):
16+
# Create arrays
17+
exprs1 = Sdf.PathExpressionArray((Sdf.PathExpression('/foo'),
18+
Sdf.PathExpression('/bar')))
19+
with self.assertRaises(TypeError,
20+
msg="Implicit conversions from string should fail"):
21+
exprs2 = Sdf.PathExpressionArray(('/foo', '/bar'))
22+
23+
# Simple use of PathExpressionArray attributes.
24+
l = Sdf.Layer.CreateAnonymous()
25+
p = Sdf.CreatePrimInLayer(l, '/foo')
26+
a = Sdf.AttributeSpec(p, 'a', Sdf.ValueTypeNames.PathExpressionArray)
27+
a.default = (Sdf.PathExpression('/foo'), Sdf.PathExpression('/bar'))
28+
self.assertEqual(a.default, exprs1)
29+
30+
if __name__ == '__main__':
31+
unittest.main()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Copyright 2025 Pixar
3+
//
4+
// Licensed under the terms set forth in the LICENSE.txt file available at
5+
// https://openusd.org/license.
6+
//
7+
#include "pxr/pxr.h"
8+
#include "pxr/usd/sdf/pathExpression.h"
9+
#include "pxr/base/vt/array.h"
10+
#include "pxr/base/vt/wrapArray.h"
11+
#include "pxr/base/vt/valueFromPython.h"
12+
13+
PXR_NAMESPACE_OPEN_SCOPE
14+
15+
namespace Vt_WrapArray {
16+
template <>
17+
std::string GetVtArrayName< VtArray<SdfPathExpression> >() {
18+
return "PathExpressionArray";
19+
}
20+
}
21+
22+
template<>
23+
SdfPathExpression VtZero() {
24+
return SdfPathExpression();
25+
}
26+
27+
PXR_NAMESPACE_CLOSE_SCOPE
28+
29+
PXR_NAMESPACE_USING_DIRECTIVE
30+
31+
void wrapArrayPathExpression() {
32+
VtWrapArray<VtArray<SdfPathExpression> >();
33+
VtValueFromPythonLValue<VtArray<SdfPathExpression> >();
34+
}

pxr/usd/sdf/wrapPathExpression.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "pxr/base/tf/pyEnum.h"
1414
#include "pxr/base/tf/pyFunction.h"
1515
#include "pxr/base/tf/pyUtils.h"
16+
#include "pxr/base/vt/wrapArray.h"
1617

1718
#include "pxr/usd/sdf/pathExpression.h"
1819
#include "pxr/usd/sdf/pathExpressionEval.h"
@@ -33,6 +34,11 @@ using PathExpr = SdfPathExpression;
3334
using ExpressionReference = PathExpr::ExpressionReference;
3435
using PathPattern = PathExpr::PathPattern;
3536

37+
TF_REGISTRY_FUNCTION(VtValue)
38+
{
39+
VtRegisterValueCastsFromPythonSequencesToArray<SdfPathExpression>();
40+
}
41+
3642
static std::string
3743
_Repr(SdfPathExpression const &self) {
3844
if (!self) {
@@ -199,6 +205,7 @@ void wrapPathExpression()
199205
.def(self == self)
200206
.def(self != self)
201207
;
208+
202209
VtValueFromPython<SdfPathExpression>();
203210

204211
TfPyWrapEnum<PathExpr::Op>();

0 commit comments

Comments
 (0)