0
$\begingroup$

In Blender Python I can add a lamp by doing the following:

DataBlock = bpy.data.lamps.new(name='HemiA', type='HEMI')
ObjHandle = bpy.data.objects.new(name='HemiA', object_data=DataBlock)
bpy.context.scene.objects.link(ObjHandle)

I want to do the same for mesh primitives such as Suzanne. There is an operator for this: bpy.ops.mesh.primitive_monkey_add(), however there doesn't seem to be any way to create a mesh primitive data block.

$\endgroup$
1
$\begingroup$

I am not sure if there are functions which return mesh primitives as a data block in the Blender API. But you can create a Suzanne data block by using a bmesh and bmesh.ops.create_monkey(bm, matrix) which you can then convert to a mesh data block

import bpy
import bmesh

bm = bmesh.new()
bmesh.ops.create_monkey(bm)

# Create mesh data block from bmesh
mesh = bpy.data.meshes.new('Mesh')
bm.to_mesh(mesh)
bm.free()

# Create object and link object to scene
obj = bpy.data.objects.new('Object', mesh)
bpy.context.scene.objects.link(obj)
bpy.context.scene.update()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.