bmesh cylinder ?

bmesh cyinder primitive don’t exist !

so how to extrude a cylinder from a bmesh circle?

http://www.blender.org/documentation/blender_python_api_2_66_4/bmesh.ops.html#module-bmesh.ops

got this circle
Add a circle XXX, should return all geometry created, not just verts.

bmesh.ops.create_circle(
bm,
cap_ends=False,
diameter=0.2,
segments=8)

not certain how to use this extrude and specify the axis ?

Extrude and create geometry on side ‘b’

ret = bmesh.ops.extrude_edge_only(
bm,
edges=edges_start_a)
geom_extrude_mid = ret[“geom”]
del ret

thanks

bmesh cylinders do exist!

bmesh.ops.create_cone(bm, cap_ends=True, cap_tris=False, segments=12, diameter1=3, diameter2=3, depth=5) # same diameter on both ends

if you want a cone:

bmesh.ops.create_cone(bm, cap_ends=True, cap_tris=False, segments=12, diameter1=3, diameter2=0, depth=5) # one diameter = 0

if you set both diameters to 0, you will get a single line pointing upwards

i did not find it on the page for bmesh !
on which page is it ?

i can use it

it still would be interesting to be able to do it from a circle as example
for extruding with geom like other example on wiki page

got another problem in a for loop where i have a square root
depending on parameters i can get a complex number
and not very good

could not find a is_complex for complex number
so is there another way to detect a complex number and let say skip and simply print an error message with some parameters values and keep doing the for loop

thanks

http://www.blender.org/documentation/blender_python_api_2_66_4/bmesh.ops.html#bmesh.ops.create_cone

import bpy, bmesh

bm = bmesh.new()


ret = bmesh.ops.create_circle(
bm,
cap_ends=False,
diameter=0.2,
segments=8)


"""
edges = []
for vert in ret['verts']:
    for edge in vert.link_edges:
        if edge not in edges:
            edges.append(edge)
ret = bmesh.ops.extrude_edge_only(bm, edges=edges)
"""


# 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))


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()
val = (12j+34)
if isinstance(val, complex):
    print("It's a complex value!")

you mean that the second diameter can be used to make the other end and get a cylinder!

the example in wiki bmesh page
added faces i think
yours don’t
so how can this be added

is it with the

faces = [bm.faces.new(verts)] # This makes one face NGON?

by the way i saw a note in wiki page that you need to free bmesh after working with it!
but did not see it in your example!
is it necessary ?

thanks

as my script doesn’t use a possibly freed bm reference, nor uses a wrapped editmesh, it’s fine here to not free it. You could do it of course:

# if you did changes to a wrapped editmesh:
#bmesh.update_edit_mesh(me)
bm.free()
del bm

You could just add circle with cap initially, then you’ll get caps on both ends after edge extrude.

bmesh.ops.create_circle(bm,
cap_ends=True, # !!!
diameter=0.2,
segments=8)

Or create face from the extruded verts:

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))

bm.faces.new(verts)

Bmesh module doesn’t care about Ngons and Non-Ngons, you can supply whatever amount of verts to faces.new(), but at least 3.

3 = triangle
4 = quad
5+ = ngon

not certain here what does
a wrapped editmesh
means ?
is it like going into edit mode ?

i’ll experiment with these new examples

i did some testing with the example in wiki page
add a bmesh circle then it does a spin

a tried this with a cross section i did an it did not work
not certain what the process is here ?

i did find a way to make it work but it is proably not the proper way




##
 
class gabrielhorn1(bpy.types.Operator):
 
 '''Add  Gabrielhorn'''
 
 bl_idname = "mesh.primitive_gabrielhorn_add"
 bl_label = "Add  Gabrielhorn"
 bl_options = {'REGISTER', 'UNDO','BLOCKING'}
 
 segh1 = IntProperty(name="Segments",description="Number  segments",default=32, min=4, max=100)
 segv1 = IntProperty(name="Segments",description="Number  segments",default=12, min=4, max=100)
 diammax= FloatProperty(name="diammax",description="diammax",default=2, min=1, max=100.0)
 diammin= FloatProperty(name="diammin",description="diammin",default=0.1, min=0.01, max=100.0)
 
 def execute(self, context):
 
  global  layers
  verts,edges,faces,vid= [],[],[],0
  bm = bmesh.new()         # Create new Bmesh mesh
  named1="Gabrielhorn"
 
  segh1 = self.properties.segh1
  segv1 = self.properties.segv1
  diammax= self.properties.diammax
  diammin= self.properties.diammin
 
# Y =  1/ x  then Spin around X axis to get Gabriel horn
 
  minag,maxag=diammax,1/diammin
  step1=(maxag-minag)/(segh1)
 
  print ('minag =',minag,'maxag =',maxag,' step1 =',step1)
 
  for n1 in float2_range(minag, maxag, step1):
 
   XC=n1
   YC=1/XC
   ZC=0
 
   print ('N1 =',n1,'XC=',XC,'YC=',YC,' vid=',vid)
 
   verts.append(bm.verts.new((XC,YC,ZC)))    # Add vertices
 
   if vid > 0:           # Add edges
    print (' vid=',vid,' vid-1=',vid-1)
    edges.append(bm.edges.new((bm.verts[vid-1], bm.verts[vid])))
   vid+= 1
 
 # SPIN 360
 
  ret = bmesh.ops.duplicate(
    bm,
    geom=bm.verts[:] + bm.edges[:] + bm.faces[:])
 
  geom_dupe = ret["geom"]
  verts_dupe = [ele for ele in geom_dupe if isinstance(ele, bmesh.types.BMVert)]
  del ret
 
  bmesh.ops.rotate(
    bm,
    verts=verts_dupe,
    cent=(0.0, 0.0, 0.0),
    matrix=Matrix.Rotation(radians(360.0), 3, 'X'))
 
  edges_start_a = bm.edges[:]
  geom_start_a = bm.verts[:] + edges_start_a
 
 
  ret = bmesh.ops.spin(
    bm,
    geom=geom_start_a,
    angle=radians(360.0),
    steps=8,
    axis=(1.0, 0.0, 0.0),
    cent=(0.0, 0.5, 0.0))
  edges_end_a = [ele for ele in ret["geom_last"]
        if isinstance(ele, bmesh.types.BMEdge)]
  del ret

 
 
 
 
  adddata1(bm,named1,verts)
 
  
  return {'FINISHED'}
 


here i simplified the script
and added a function to add ob/mesh to scene

is there a shorter way to make the spin 360 degrees around an axis
with the spin command or may be use the other command for rotate around an axis?

thanks

not certain here what does
a wrapped editmesh
means ?
is it like going into edit mode ?

Not at all. Usually, Bmesh objects own their data. But if a mesh is in edit mode, you can wrap that editmesh and work with it (bmesh.from_edit_mesh). The is_wrapped property will then be true, and you can use it to check if you need to flush data (bmesh.update_edit_mesh) in case you support both, edit and object mode.

i remove the rotate part in little example and seems to also work!

you have given an example to make faces

import bpy, bmesh

bm = bmesh.new()

v1 = bm.verts.new((0,0,0)) # add a new face = triangle
v2 = bm.verts.new((1,0,0))
v3 = bm.verts.new((1,1,0))

print (‘v1=’,v1, ‘v2=’,v2,‘v3=’,v3)
print ()

bm.faces.new((v1, v2, v3))

bm.normal_update()
bmesh.update_edit_mesh(me, True, True)

me.update()


here when you pass verts location in var V1–V3
does this add new verts to the bmesh verts ?

cause in other example you use this method instead
verts.append(bm.verts.new((XC,YC,ZC)))

now tryng to make face by face for quad as i make 4 verts

is there a way to spec the verts index to make one face using verts index ?

i saw make a pyramide model
using this method but not certain what the BVs[] are

bm.faces.new([bvs[i], bvs[i+n], bvs[i+n+1], bvs[i+1]])

are these verts index may be?

thanks

dunno what you mean…

bm.verts.new(…) adds a new vertex to bm and returns a reference to that vert. If you need couple verts later for other operations, then it’s a good idea to append the refs to a list.

ok i see list now but this is not a simple list it is a bmesh verts list!

now how about making faces tris or quad using index from vert list is it possible

like in some case i need to make faces function of the verts index i have in a for loop ?

i did a panel using properties for tool pro panel and
i try to assign a calculated value to the string property
but it is refusing to update in tool panel
is there something special to do the update here?

or how do you add a like a label property where i can dump some values ?
i could use a scene propertie to do that if necessary may be!

all the other properties seems to work fine but i’m changing the button itself not assigning value

thanks

it is a simple python list. It stores bmesh verts objects / references, but there is still nothing special about the list.

if you wanna use the vert list, you could do e.g.:

every_other_vert = []
for i, vert in enumerate(verts):
    if i % 2 == 0:
        every_other_vert.append(vert)

#or

few_verts = [verts[0], verts[3], verts[5], verts[6]]

not sure how you do the panel / update, maybe you miss a manual tag_redraw()

i’m using the add mesh method here with properties in tool-pro panel

not certain if you can add like a label there and put values in it
might need to use a panel instead of a class operator

i can do it in a panel but i’m using class operator here

i might be able to add a tool pro panel and pass the info in the panel
but this means this panel would be there for all class operator
which is not what i want
i need this little info for some of the class operator only!

thanks

what shows in tool prop panel are the operator’s properties. What happens if you change a value there is, that the operator is undone and executed again with different params. If you need to adjust the layout of the tool props panel, adding a draw() method to the operator should do.

i heard there was some changes for operator panel in last few months
but not certain what these changes were!

i can add a draw method but does it means that we can assign value to a propertie now ?

for that problem with complex values in a loop for verts i think i may have to add a pop up window and do a return to cancel the loop and curve being done
but even that might not be enough to cancel the error cause the properties might not be reseted !

verts index
i can see that in a loop for making verts bmehs list there is a temporary list being done with verts from bmesh
which is then use to make edge and faces
and i found 2 or 3 ways to make the faces now
but this is not like in old API the verts list does not contains the location of verts but a reference to bmesh data!
so it’s different from old API!

thanks

did some testing wiht draw method in operator class

def draw(self, context): # Function to draw the menu in tool pro panel

layout = self.layout
layout.prop(self, ‘nturn’, text=“Qty Turns”)
layout.prop(self, ‘a1’, text=“a1”)
layout.prop(self, ‘b1’, text=“step size”)
layout.prop(self, ‘ht’, text=“Height/turn”)
layout.prop(self, ‘curveadd’, text=“Height/turn”)
layout.prop(self, ‘str1’, text=“Height/turn”)

str1= self.properties.str1

pas1=2piself.properties.b1
print ()
print (’{0:.5}’.format(pas1))
print ()
str1=str(’{0:.5}’.format(pas1)) # assing value to label
print (‘str1’,str1)

but it does not change the property value in tool pro panel?
but propr seems to change when i print it on console

so how do you update it in tool pro panel ?

thanks

i see, you wanna change the actual property value

but writing to ID classes isn’t allowed there, you can use another operator or e.g. an enumprop with an update callback that change prop values.

Here are 2 techniques which seem to work:

import bpy



def main(context):
    for ob in context.scene.objects:
        print(ob)




class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    prop = bpy.props.IntProperty()


    @classmethod
    def poll(cls, context):
        return context.active_object is not None


    def execute(self, context):
        main(context)
        return {'FINISHED'}
    
    def draw(self, context):
        self.layout.prop(self, "prop")
        
        self.layout.operator(self.bl_idname, text="Set to 1337").prop = 1337
        
        props = self.layout.operator("wm.context_set_int", text="Set to 1234")
        props.data_path = "active_operator.prop"
        props.value = 1234
        




def register():
    bpy.utils.register_class(SimpleOperator)




def unregister():
    bpy.utils.unregister_class(SimpleOperator)




if __name__ == "__main__":
    register()



not working added import prop
but even with that nothing appears in tool pro panel!

interesting but never seen this before how is this working ?

i found another way using label in panel draw method to do it and seems to work ok

thanks

thanks

works fine, you need to run Simple Operator from spacebar menu…

import bpy


def main(context):
    for ob in context.scene.objects:
        print(ob)


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    prop = bpy.props.IntProperty()


    @classmethod
    def poll(cls, context):
        return context.active_object is not None


    def execute(self, context):
        main(context)
        return {'FINISHED'}
    
    def draw(self, context):
        layout = self.layout
        
        layout.prop(self, "prop")
        layout.label("* 2 = " + str(self.prop*2))
        
        layout.operator(self.bl_idname, text="Set to 1337").prop = 1337
        
        props = layout.operator("wm.context_set_int", text="Set to 1234")
        props.data_path = "active_operator.prop"
        props.value = 1234
        


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

ok it runs
but i had to click on little triangle to see the tool pro vars !
why it does not run on automatially ?

still have to see how this works!

thanks