MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / formatDefaultValue

Function formatDefaultValue

python/Scripts/comparenodedefs.py:310–333  ·  view source on GitHub ↗

Format a default value for display using spec notation (__zero__, etc.).

(value, valueType, geompropNames)

Source from the content-addressed store, hash-verified

308 return None, False
309
310def formatDefaultValue(value, valueType, geompropNames):
311 '''Format a default value for display using spec notation (__zero__, etc.).'''
312 if value is None:
313 return 'None'
314
315 # Handle string values (geomprops, empty strings, etc.)
316 if isinstance(value, str):
317 if value in geompropNames:
318 return f'_{value}_'
319 return '__empty__' if value == '' else value
320
321 # Check if value matches a standard constant (__zero__, __one__, __half__)
322 for placeholder, display in [('0', '__zero__'), ('1', '__one__'), ('0.5', '__half__')]:
323 expansion = expandDefaultPlaceholder(placeholder, valueType)
324 if expansion is None:
325 continue
326 try:
327 if value == mx.createValueFromStrings(expansion, valueType):
328 return display
329 except Exception:
330 pass
331
332 # Fall back to string representation
333 return str(value)
334
335
336# -----------------------------------------------------------------------------

Callers 1

compareSignatureDefaultsFunction · 0.85

Calls 4

isinstanceFunction · 0.85
expandDefaultPlaceholderFunction · 0.85
strClass · 0.85

Tested by

no test coverage detected