[Bf-python] Object/Mesh constructors
David Jagoe
davidjagoe at gmail.com
Fri Jul 16 17:56:46 CEST 2010
Hi Campbell,
On 8 July 2010 15:36, Campbell Barton <ideasman42 at gmail.com> wrote:
> mesh = bpy.data.meshes.new(name="Foo")
> obj = bpy.data.objects.new(name="Foo", object_data=mesh)
> bpy.context.scene.objects.link(obj)
Thanks for your quick response, this seems to be exactly what I'm
after. Your example seems to work as expected, and creates a mesh with
0 vertices. I have been experimenting with adding vertices and faces -
so far without success. I came across the following code:
# me = bpy.data.meshes.new()
# ob = sce.objects.new(me)
# me.verts.extend([V(bb[0]).resize3D(), V(bb[1]).resize3D(),
V(bb[2]).resize3D(), V(bb[3]).resize3D()])
# me.faces.extend([(0,1,2,3),])
# me.verts.extend([V(uv[0]).resize3D(), V(uv[1]).resize3D(),
V(uv[2]).resize3D()])
# me.faces.extend([(4,5,6),])
Which doesn't work in blender 2.5:
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'bpy_prop_collection' object has no attribute 'extend'
So I tried the following:
>>> mesh.add_geometry(verts=4, edges=4, faces=1)
After which I can manipulate the vertices but there are no faces or edges:
>>> mesh.faces
<bpy_collection[0], Mesh.faces>
>>> mesh.edges
<bpy_collection[0], Mesh.edges>
Any advice? My final goal is to end up with a rectangular plane in
that same way as doing Add > Mesh > Plane in the GUI would do.
Thanks again.
Cheers,
David
>
> On Thu, Jul 8, 2010 at 2:57 PM, David Jagoe <davidjagoe at gmail.com> wrote:
>> G'day all,
>>
>> Is there a better way to add an object than using bpy.ops.object_add
>> or (e.g) bpy.ops.mesh.primitive_plane_add?
>>
>> I've tried to use bpy.types.Mesh.
>>
>> Ideally I would like something like a normal factory or constructor
>> method that returns the object to me so that I can manipulate it
>> further. I imagine that such a facility must exist but I can't seem to
>> find it.
>>
>>
>> Thanks,
>> David
>> _______________________________________________
>> Bf-python mailing list
>> Bf-python at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-python
>>
>
>
>
> --
> - Campbell
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
More information about the Bf-python
mailing list