1
$\begingroup$

Let’s say I created a bunch of these cones in my_bmesh object:

c = bmesh.ops.create_cone(my_bmesh, segments=8, diameter1=1, diameter2=1, cap_ends=True)

Is there a way to access a cone’s edges (preferably right after I create it) so I could connect it with other cones using bridge edge loops?

$\endgroup$
  • $\begingroup$ As Develepper myself, dynamically created object generate a random name. if you want to access them in code, you will need to use a specific sequenceand name it with that sequence. like c.Name ='my_bmesh' + [int value used as increment and stored somewhere like global variable] $\endgroup$ – Eric Brochu Jul 21 at 16:24
  • $\begingroup$ I don't need to name the objects; i want to connect two subsequently created cones. The problem is, bmesh.ops.create_cone() returns only a dict of vertices (AFAIK). $\endgroup$ – blusher Jul 21 at 16:33
  • $\begingroup$ Each vertex of bmesh has its corresponding edges. $\endgroup$ – lemon Jul 21 at 16:47
  • $\begingroup$ And how can I get these edges? $\endgroup$ – blusher Jul 21 at 17:03
  • $\begingroup$ Maybe... read the doc a bit and enhance your question when you've tried something. See docs.blender.org/api/current/… and docs.blender.org/api/current/… $\endgroup$ – lemon Jul 21 at 17:13
1
$\begingroup$

Slice based on pre op lengths

It is my experience that new geometry is always appended after using the bmesh create operators.

Hence can look at the length of bm.faces before, and use to slice after.

A more robust result could be achieved with sets of elements prior and after.

import bpy
import bmesh
ob = bpy.context.object
me = ob.data
bm = bmesh.new()
bm.from_mesh(me)

nv, ne, nf = (len(bm.verts), len(bm.edges), len(bm.faces))
ret = bmesh.ops.create_cone(bm, 
        segments=3, 
        diameter2=2,
        depth=1,
        cap_ends=True)

print(len(bm.verts[nv:]), "New Verts:", [g.index for g in bm.verts[nv:]])
# check if new verts slice and op return are the same
same_verts = not bool(set(bm.verts[nv:]) - set(ret['verts']))
print("Slice and op return same verts?", same_verts)
print(len(bm.edges[ne:]), "New Edges:", [g.index for g in bm.edges[ne:]])
print(len(bm.faces[nf:]), "New faces:", [g.index for g in bm.faces[nf:]])

''' Result

4 New Verts: [8, 9, 10, 11]
Slice and op return same verts? True
6 New Edges: [12, 13, 14, 15, 16, 17]
4 New faces: [6, 7, 8, 9]

'''
$\endgroup$
1
$\begingroup$

Solved it:

(prev_edges -> edges from previous cone)
c = bmesh.ops.create_cone(my_bmesh)
verts = list(c.values())[0]
curr_edges = verts[0].link_faces[0].edges
total_edges = [e for e in prev_edges] + [e for e in curr_edges]
bmesh.ops.bridge_loops(my_bmesh, edges=total_edges)
prev_edges = verts[-1].link_faces[0].edges
$\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.