How can I, in a simple line by line fashion, create i.e. a pyramid object?
How can I move specific points in a created cube to desired locations, and possibly merge 4 points sharing location to obtain a pyramid that way?
I’ve check out operator_mesh_add.py, but I’m clueless on Python and programming in general, and it seems to do a lot more than I want (add box appear in add mesh menu and so on), and I’m not able to grab what I need and put it in my own script and have it working.
Similarly I’ve looked at bmesh_simple.py, which moves all verts. I’ve watched tutorials how to stop at one vert, which works ok, but I can’t figure out the syntax how to move specific verts to specific precalculated locations.
I’ve also looked at addons, but the syntax for a complete noob is utter greek to me.
Edit: For #1, I found this which I think will help me, I can make the object I want and looks straightforward to use. Although problem solved for now, answer to #2 would still be welcome.
Old API, new API? Okay, didn’t know they had different ages Anyhow, I have created my pyramids with bmesh (vertex by vertex, given the example I found above and implemented in my “script”) and rectangle with create (and modify size and rotation). So I basically have what I need for now regarding objects I want to create in the scene (although there is still lots to do like linking in and assigning material libraries, linking in and positioning objects).
So yeah, I’m still learning. But still, given the default cube in the fabric startup, how do I relocate vertex #2 and #5 to some new positions? I’m basically after the basic syntax here.
make a cylinder
import bpy, bmesh
bm = bmesh.new()
ret = bmesh.ops.create_circle( # Add a new circle
bm,
cap_ends=False,
diameter=0.2,
segments=8)
# We can do simpler in this case, just use all edges
ret = bmesh.ops.extrude_edge_only(bm, edges=bm.edges)
verts = [v for v in ret['geom'] if isinstance(v, bmesh.types.BMVert)]
bmesh.ops.translate(bm, verts=verts, vec=(0, 0, 2.5))
# add new object to scene
me = bpy.data.meshes.new("Mesh")
bm.to_mesh(me)
ob = bpy.data.objects.new("Cone", me)
bpy.context.scene.objects.link(ob)
bpy.context.scene.update(
move verts
If you just want to move a vertex to a new position, and you know what that position is, it's simpler to assign the coordinates directly:
v = bmesh.verts[i]
v.co = Vector( [x,y,z] )
if you want to move it relative to its current position, just add values to its current coordinates:
v.co = v.co + Vector( [ dx, dy, dz ] )
1st example:
verts = [v for v in ret[‘geom’] if isinstance(v, bmesh.types.BMVert)]
What the heck is v and what does this even mean? In English I mean. Again, I’m completely new to programming, haven’t really done it since the 6510 (34 years ago according to wiki, lol).
2nd example:
for v in bm.verts:
if v.index % 3 == 0:
v.index is probably what I’m looking for, but where does index come from? I thought [] was how to access arrays. And, do I really have to go through the whole thing? Is there no way to access them directly, like (plain English) vert[2] setcoord (x,y,z) or something?