Skip to content

pytha.find_material

fabian-flassig edited this page Aug 25, 2026 · 2 revisions

Finds an existing material in the current PYTHA document by name.

Scans the document's material list and returns an element handle for the first material whose name matches exactly. Returns nil if no material with that name exists.

pytha.find_material(name)
Parameter Type Description
name string Exact material name to search for (case-sensitive).

Return value:

Type Description
element_handle An element handle of type "material" for the found material, or nil if not found.

Notes:

  • The search is exact and case-sensitive, consistent with how PYTHA stores and displays material names.
  • Use this function to locate a material before modifying it with set_element_attributes or assigning it with set_element_material, rather than creating a duplicate via create_material.

Example:

local mat = pytha.find_material("Brass")
if mat then
    pytha.set_element_attributes(mat, { reflective = 0.9, update_thumbnail = true })
end

Assign an existing material to a new part, or create it if it does not exist yet:

local mat = pytha.find_material("Glass") or pytha.create_material("Glass", {
    color           = { 0.9, 0.95, 1.0 },
    transparent     = 0.85,
    refractive_index = 1.5,
    glossiness      = 0.95,
    update_thumbnail = true,
})
pytha.set_element_material(part, mat)

Version Support:

Minimum PYTHA Version: V27

See also:

pytha, element handles, create_material, enumerate_materials, set_element_material, set_element_attributes

Clone this wiki locally