0
$\begingroup$

I add 1 circle using this code

ret = bmesh.ops.create_circle(
        bm,
        cap_ends=False,
        radius=(10),
        segments=3,
        )
del ret
edges_start_a = bm.edges[:]
geom_start_a = bm.verts[:] + edges_start_a
verts_start_a = bm.verts[:]

When i add a second one using the same code only different variables

ret = bmesh.ops.create_circle(
        bm,
        cap_ends=False,
        radius=(10),
        segments=3,
        )
del ret
edges_start_b = bm.edges[:]
geom_start_b = bm.verts[:] + edges_start_b
verts_start_b = bm.verts[:]

All the variables of the second circle is combined with the first one I.E. edges_start_b also has edges of edges_start_a in it

How can i split these? Or at least get the vertices and edges and faces of each individual circle?

$\endgroup$

1 Answer 1

3
$\begingroup$

I'm assuming, that bm is a bmesh object. Obviously, the bmesh object will hold all verts, edges and faces that you add to it with any operation.

You should improve the following

  1. Don't del ret. It should be put in a global scope where ret is accessible later anyways. If it goes out of scope python will delete it automatically. You're using a dynamic interpreter language, so you can use its features. Even just not pointing to the return variable bmesh.ops.create_circle(bm, ... ) will delete the pointer.
  2. Your code won't compile. Always post working code snippets (mwe) in question. You'll be saving everyone a lot of time. (A) Others won't have to rewrite your code and (B) your problem may be in the code you didn't post.
  3. Read the documentation. The method bmesh.ops.create_circle actually return a dictionary with the newly created vertices.

From the api:

Returns
verts: output verts type list of (bmesh.types.BMVert)

Return type
dict with string keys

With the returned dict we can point to the verts. (Obviously, now that we're using the returned object ret don't delete it.)

verts = ret['verts']

Each vertex stores the linked edges.

verts[0].link_edges

The updated snippet could look like this.

import bmesh

bm = bmesh.new()

ret = bmesh.ops.create_circle(
        bm,
        cap_ends=False,
        radius=(10),
        segments=5,
        )
verts = ret['verts']

edges = set()
for vert in verts:
    for edge in vert.link_edges:
        edges.add(edge)

edges = list(edges)

So, what's going on at the end? Why are we creating a set() and then converting it to a list?

Each vertex of the circle, will have two link_edges. However, the connected vertices will share an edge. This means, that if we just add all of the linked edges into a big list, each edge will show up twice. That's why, I use a python set. In a set each element is unique. Adding items to a set with the add() method will not do anything if the element (the next edge) is already present in the set.

$\endgroup$
6
  • 1
    $\begingroup$ Thanks for your answer learned from it Following this example docs.blender.org/api/master/… The operator example does delete ret whole time. so that's why I also did it $\endgroup$
    – cexoso
    Commented Dec 29, 2019 at 11:58
  • 1
    $\begingroup$ Yes, I saw that. I think they del the ret variable, because they're assigning it another value in the next line and want to avoid confusion. By using del they are saying that whatever was in this variable is no longer used, although the same variable name shows up shortly after. You can read it here: using del can be useful to show intent. - I know in the case of del foo that the intent is to remove the variable from scope. It's not clear that foo = None is doing that. $\endgroup$
    – Leander
    Commented Dec 29, 2019 at 12:09
  • $\begingroup$ Btw, welcome to Blender.SE. If this answer solved your question, you can tick the checkmark to the top-left of the answe.r $\endgroup$
    – Leander
    Commented Dec 29, 2019 at 12:13
  • $\begingroup$ Thanks for welcoming me.I have 1 more question related to this the list that I get back is different [<BMEdge(0x000001650DE89220), index=3, verts=(0x000001657B5F0130/4, 0x000001657B5F00F8/3)>] {<BMEdge(0x000001650F812690), index=9, verts=(0x000001657B5F01D8/7, 0x000001657B5F01A0/6)>} See the second list I got using your code It closes with } instead of with ] Any idea how to fix this ? $\endgroup$
    – cexoso
    Commented Dec 29, 2019 at 12:15
  • $\begingroup$ Added a new paragraph, clearer now? $\endgroup$
    – Leander
    Commented Dec 29, 2019 at 12:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .