pyvista.set_new_attribute#
- set_new_attribute(obj: object, name: str, value: Any) None [source]#
Set a new attribute for this object.
Python allows arbitrarily setting new attributes on objects at any time, but PyVista’s classes do not allow this. If an attribute is not part of PyVista’s API, an
AttributeError
is normally raised when attempting to set it.Use
set_new_attribute()
to override this and set a new attribute anyway.Examples
Set a new custom attribute on a mesh.
>>> import pyvista as pv >>> mesh = pv.PolyData() >>> pv.set_new_attribute(mesh, 'foo', 42) >>> mesh.foo 42
Added in version 0.46.