Skip to content

Commit

Permalink
Revised example code in utility functions of PyMaterialXCore. (#1567)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Habel <19556655+StefanHabel@users.noreply.github.com>
  • Loading branch information
StefanHabel committed Oct 21, 2023
1 parent 86030d0 commit 90c78d4
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions source/PyMaterialX/PyMaterialXCore/PyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ void bindPyUtil(py::module& mod)
PYMATERIALX_DOCSTRING(R"docstring(
Return the version of the MaterialX library as a string.
>>> PyMaterialXCore.getVersionString()
>>> import MaterialX as mx
>>> mx.getVersionString()
'1.38.9'
The resulting version is also available in the `__version__` attribute of
the `MaterialX` Python package:
>>> import MaterialX
>>> MaterialX.__version__
'1.38.9'
)docstring"));

Expand All @@ -28,7 +36,8 @@ void bindPyUtil(py::module& mod)
Return the major, minor, and build versions of the MaterialX library as an
integer tuple.
>>> PyMaterialXCore.getVersionIntegers()
>>> import MaterialX as mx
>>> mx.getVersionIntegers()
(1, 38, 9)
)docstring"));

Expand All @@ -38,7 +47,8 @@ void bindPyUtil(py::module& mod)
Create a valid MaterialX name from the given `name`,
replacing invalid characters with the given `replaceChar`.
>>> PyMaterialXCore.createValidName('left arm #123')
>>> import MaterialX as mx
>>> mx.createValidName('left arm #123')
'left_arm__123'
)docstring"));

Expand All @@ -48,7 +58,8 @@ void bindPyUtil(py::module& mod)
Return `True` if the given `name` is a valid MaterialX name,
otherwise False.
>>> PyMaterialXCore.isValidName('left arm #123')
>>> import MaterialX as mx
>>> mx.isValidName('left arm #123')
False
)docstring"));

Expand All @@ -57,7 +68,8 @@ void bindPyUtil(py::module& mod)
PYMATERIALX_DOCSTRING(R"docstring(
Increment the numeric suffix of the given `name`.
>>> PyMaterialXCore.incrementName('left arm #123')
>>> import MaterialX as mx
>>> mx.incrementName('left arm #123')
'left arm #124'
)docstring"));

Expand All @@ -67,7 +79,8 @@ void bindPyUtil(py::module& mod)
Split the given `string` into a list of substrings using the
given set of separator characters.
>>> PyMaterialXCore.splitString('MaterialX', 'aeiou')
>>> import MaterialX as mx
>>> mx.splitString('MaterialX', 'aeiou')
['M', 't', 'r', 'lX']
)docstring"));

Expand All @@ -77,7 +90,8 @@ void bindPyUtil(py::module& mod)
Join a list of substrings into a single string, placing the
given separator between each substring.
>>> PyMaterialXCore.joinStrings(['M', 'teri', 'lX'], 'a')
>>> import MaterialX as mx
>>> mx.joinStrings(['M', 'teri', 'lX'], 'a')
'MaterialX'
)docstring"));

Expand All @@ -86,7 +100,8 @@ void bindPyUtil(py::module& mod)
PYMATERIALX_DOCSTRING(R"docstring(
Apply the given substring `substitutions` to the input `string`.
>>> PyMaterialXCore.replaceSubstrings(
>>> import MaterialX as mx
>>> mx.replaceSubstrings(
... '/bob/alice/guido',
... {'bob': 'b', 'alice': 'a', 'guido': 'g'}
... )
Expand All @@ -99,9 +114,10 @@ void bindPyUtil(py::module& mod)
Return `True` if the given `string` starts with the given `prefix`,
otherwise `False`.
>>> PyMaterialXCore.stringStartsWith('turbulence3d', 'turbulence')
>>> import MaterialX as mx
>>> mx.stringStartsWith('turbulence3d', 'turbulence')
True
>>> PyMaterialXCore.stringStartsWith('turbulence3d', 'Turbulence')
>>> mx.stringStartsWith('turbulence3d', 'Turbulence')
False
)docstring"));

Expand All @@ -111,9 +127,10 @@ void bindPyUtil(py::module& mod)
Return `True` if the given `string` ends with the given `suffix`,
otherwise `False`.
>>> PyMaterialXCore.stringEndsWith('turbulence3d', '3d')
>>> import MaterialX as mx
>>> mx.stringEndsWith('turbulence3d', '3d')
True
>>> PyMaterialXCore.stringEndsWith('turbulence3d', '3D')
>>> mx.stringEndsWith('turbulence3d', '3D')
False
)docstring"));

Expand All @@ -122,7 +139,8 @@ void bindPyUtil(py::module& mod)
PYMATERIALX_DOCSTRING(R"docstring(
Split the given `namePath` into a list of names.
>>> PyMaterialXCore.splitNamePath('/robot2/right_arm')
>>> import MaterialX as mx
>>> mx.splitNamePath('/robot2/right_arm')
['robot2', 'right_arm']
)docstring"));

Expand All @@ -131,7 +149,8 @@ void bindPyUtil(py::module& mod)
PYMATERIALX_DOCSTRING(R"docstring(
Create a name path from the given list of `names`.
>>> PyMaterialXCore.createNamePath(['robot2', 'right_arm'])
>>> import MaterialX as mx
>>> mx.createNamePath(['robot2', 'right_arm'])
'robot2/right_arm'
)docstring"));

Expand All @@ -140,7 +159,8 @@ void bindPyUtil(py::module& mod)
PYMATERIALX_DOCSTRING(R"docstring(
Given a `namePath`, return the parent name path.
>>> PyMaterialXCore.parentNamePath('/robot2/right_arm')
>>> import MaterialX as mx
>>> mx.parentNamePath('/robot2/right_arm')
'robot2'
)docstring"));
}

0 comments on commit 90c78d4

Please sign in to comment.