This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
blender:blenderdata [2017/11/21 18:15] dwheele [Data Access] |
blender:blenderdata [2017/11/21 18:26] (current) dwheele [Data Access] |
||
|---|---|---|---|
| Line 12: | Line 12: | ||
| ===== Data Access ===== | ===== Data Access ===== | ||
| - | === Object ==== | + | ==== Object ==== |
| === To get an existing object: === | === To get an existing object: === | ||
| Line 80: | Line 80: | ||
| </ | </ | ||
| + | ==== Polygons ==== | ||
| + | Brief example | ||
| + | |||
| + | <code python> | ||
| + | for p in ob.data.polygons: | ||
| + | p.material_index = ms_index | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Material ==== | ||
| + | |||
| + | Materials are established separate from Objects, then links are made from Objects to Materials. | ||
| + | |||
| + | === To get an existing material: === | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | === To create a new material: === | ||
| + | |||
| + | <code python> | ||
| + | mat = bpy.data.materials.new(name=" | ||
| + | </ | ||
| + | |||
| + | Assign material to an object **ob** | ||
| + | |||
| + | <code python> | ||
| + | if not(ob.data.materials.get(mat.name)): | ||
| + | ob.data.materials.append(mat) | ||
| + | | ||
| + | # this example adds material to all polygons in ob | ||
| + | ms_index = ob.material_slots.find(" | ||
| + | for p in ob.data.polygons: | ||
| + | p.material_index = ms_index | ||
| + | </ | ||
| + | | ||