Utility toolbelt for great convenience.
Clears the console across multiple CINEMA 4D versions.
Fuzzy string comparison.
Two strings are deemed equal if they have the same byte sequence for up to ‘limit’ chars.
Limit can be an int or a percentage string like for example 60% in which case 2 strings are deemed equal if at least 60% relative to the longest string match.
CINEMA 4D R12’s CPython integration stores high-order chars (ord > 126) as 4-byte unicode escape sequences with upper case hex letters.
For example the character ä (LATIN SMALL LETTER A WITH DIAERESIS) would be stored as the byte sequence \u00E4. This function replaces high-order chars with a unicode escape sequence suitable for CINEMA 4D R12.
If you use this function in R12 you probably need to balance each call with a call to UnescapeUnicode() when the time comes to use, display or compare your string to a string returned by some internal function of C4D R12.
For example, if you ask an object named Würfel (German for cube) for its name:
opname = op.GetName()
# opname now prints as "W\ürfel" but is actually "W\u00FCrfel"
# if you UnescapeUnicode now you will get a Python byte string
# with proper encoding
opname_unescaped = UnescapeUnicode(opname)
# opname_unescaped is now "W\xfcrfel" (latin-1) and you can compare
# it to other Python byte strings with no additional fuzz. If you want
# to change the byte string and then pass it to C4D to set an object's
# new name you would have to escape the byte string to get a string
# that uses an escape sequence similar to the one shown at the beginning
new_opname_escaped = EscapeUnicode(opname_unescaped)
op.SetName(new_opname_escaped)
# Remember this is only relevant for R12. In R13 and R14 both functions
# are practically no-ops.
In R13 and R14 it returns the string untouched since in those versions the CPython intergration handles Unicode encoded strings properly.
CINEMA 4D R12’s CPython integration stores high-order chars (ord > 126) as 4-byte unicode escape sequences with upper case hex letters.
This function converts unicode escape sequences used by CINEMA 4D when passing bytes (e.g. \u00FC -> \xfc) to their corresponding high-order characters.
It should be used in R12 only and should balance out any calls made to EscapeUnicode().
In R13 and R14 the string is returned untouched since in those versions the CPython intergration handles Unicode encoded strings properly.
(x,y,z, .. n) -> 'x.y.z...n'
Returns a pretty-printed string of a list<list> structure.
Convenience function for firing off commands to the system console. Used instead of subprocess.call so that shell variables will be expanded properly.
Not the same as os.system as here it captures stdout and stderr in a tuple for Python 2.5 and lower or a namedtuple in 2.6 and higher. So you can use result[0] in the first case and result.out in the second.
Parameters: |
|
---|---|
Returns: | tuple or namedtuple |
A decorator that prints the time a function takes to execute per call and cumulative total.
Accepts the following keyword arguments
Parameters: |
|
---|
For convenience you can also set attributes on the benchmark function itself with the same name as the keyword arguments and the value of those will be used instead. This saves you from having to call the decorator with the same arguments each time you use it. Just set, for example, benchmark.prec = 5 after the import and before you use it for the first time.
Usage example:
@benchmark
def factorial(x):
''' Return factorial of x. '''
result = 1
for i in range(x):
result = result * (i + 1)
return result
Output:
-> factorial() @ 001: 10.000 us, total: 10.000 us
-> factorial() @ 002: 22.000 us, total: 32.000 us
Output for @benchmark(unit='ms', time_width=6):
-> factorial() @ 001: 0.009 ms, total: 0.009 ms
-> factorial() @ 002: 0.023 ms, total: 0.032 ms
Decorator that enforces types for function/method args.
Two ways to specify which types are required for each arg.
None is always a valid type, to allow for optional args.
Usage example:
@require(x=int, y=float)
def func(x, y):
return x / y
Can be used to mark functions as deprecated.
Parameters: |
|
---|
Classic cache decorator.
Classic memoization decorator.