User Tools

Site Tools


blender:blenderdata

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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("Card Face") vg = ob.vertex_groups.new("Card Face")
 vg.add([0,1,2,3],1,"ADD") vg.add([0,1,2,3],1,"ADD")
-# 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
 </code> </code>
  
 +==== Polygons ====
  
 +Brief example
 +
 +<code python>
 +for p in ob.data.polygons:
 +  p.material_index = ms_index
 +</code>
 +
 +
 +==== Material ====
 +
 +Materials are established separate from Objects, then links are made from Objects to Materials.
 +
 +=== To get an existing material: ===
 +
 +  * ''mat = bpy.data.materials["Material"]''
 +  * ''mat= bpy.data.materials.get("Material")'' # If not found, returns None gracefully
 +
 +=== To create a new material: ===
 +
 +<code python>
 +mat = bpy.data.materials.new(name="Card Paper")
 +</code>
 +
 +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("Card Paper")
 +  for p in ob.data.polygons:
 +    p.material_index = ms_index
 +</code>
 +    
  
blender/blenderdata.1511288092.txt.gz · Last modified: 2017/11/21 18:14 by dwheele