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:07] dwheele |
blender:blenderdata [2017/11/21 18:26] (current) dwheele [Data Access] |
||
|---|---|---|---|
| Line 14: | Line 14: | ||
| ==== Object ==== | ==== Object ==== | ||
| - | To get an existing object: | + | === To get an existing object: |
| * '' | * '' | ||
| Line 20: | Line 20: | ||
| * '' | * '' | ||
| - | To create a new object: | + | === To create a new object: |
| * Create a datablock with '' | * Create a datablock with '' | ||
| Line 51: | Line 51: | ||
| </ | </ | ||
| + | === Vertex Groups === | ||
| + | <code python> | ||
| + | for vertexGroup in ob.vertex.groups: | ||
| + | print vertexGroup.name | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | After establishing a group, you can add vertices to it: | ||
| + | |||
| + | <code python> | ||
| + | verts = ((x,y,z), (x+w, y,z), (x+w, | ||
| + | (x,y+t,z), (x+w, | ||
| + | faces = ((0,1,2,3), (5,4,7,6), (5,6,2,1), (6,7,3,2), (7,4,0,3), (4,5,1,0)) | ||
| + | me = ob.data | ||
| + | me.name = name+' | ||
| + | |||
| + | # Create mesh from given verts, faces. | ||
| + | me.from_pydata(verts, | ||
| + | # Update mesh with new data | ||
| + | me.update() | ||
| + | | ||
| + | vg = ob.vertex_groups.new(" | ||
| + | vg.add([0, | ||
| + | # 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 | ||
| + | </ | ||
| + | | ||