# Set object material in Python

**URL:** <https://discourse.mcneel.com/t/set-object-material-in-python/123978>\
**Category:** Scripting\
**Tags:** windows, material, python\
**Created:** [May 10, 2021, 3:52pm UTC](https://discourse.mcneel.com/t/set-object-material-in-python/123978 "2021-05-10T15:52:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Tim\_Williams](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tim_williams/32/472277_2.png) [@Tim\_Williams](https://discourse.mcneel.com/u/Tim_Williams)\
**Post date:** [May 11, 2021, 5:05pm UTC](https://discourse.mcneel.com/t/set-object-material-in-python/123978/2 "2021-05-11T17:05:53Z")

</div>

Realized I can do it in a less fancy way:

> def AssignMaterialFast():  
> ids = rs.GetObjects(“Select object to change material”, preselect=True)  
> if ids is None:  
> return
> 
> ```
> rmats = [rm for rm in sc.doc.RenderMaterials]
> materialNames = []
> for mat in rmats:
> materialNames.append(mat.Name)
> 
> materialNames.sort()
> result = rs.ListBox(materialNames, "Select Material", "Assign Material")
> if result is None: return
> 
> rs.SelectObjects(ids)
> cmdString = "-_RenderAssignMaterialToObjects " + result + " "
> rs.Command(cmdString, False)
> 
> ```

---

_[View the full topic](https://discourse.mcneel.com/t/set-object-material-in-python/123978)._
