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:14] dwheele [Object] |
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 76: | Line 76: | ||
| vg = ob.vertex_groups.new(" | vg = ob.vertex_groups.new(" | ||
| vg.add([0, | vg.add([0, | ||
| - | # The indexes 0,1,2,3 are referring to the vertices in the order they are added to the object | + | # The indexes 0,1,2,3 are referring to the vertices |
| + | # in the order they are added to the object | ||
| </ | </ | ||
| + | ==== 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 | ||
| + | </ | ||
| + | | ||