0
$\begingroup$

I want to program a tool for checking radial parts of a mesh.

The idea is: You push a button, the scripts add an object (circle) to the scene. Then you grab it place it and when you scale this circle it changes segments depending on the diameter.

I'm stuck on this for now

import bpy
import bmesh
import math
import mathutils

class OPA(bpy.types.Operator):
# Make a new BMesh
    bm = bmesh.new()


# Add a circle XXX, should return all geometry created, not just verts.
    bmesh.ops.create_circle(
        bm,
        cap_ends=True,
        cap_tris=True,
        diameter=2,
        segments=8)

# Finish up, write the bmesh into a new mesh
    me = bpy.data.meshes.new("Mesh")
    bm.to_mesh(me)
    bm.free()


# Add the mesh to the scene
    scene = bpy.context.scene
    obj = bpy.data.objects.new("Object", me)
    obj.show_wire = True;
    obj.show_all_edges = True;
    obj.draw_type = "WIRE";
    scene.objects.link(obj)
    obj.location = bpy.context.scene.cursor_location


# Select and make active
    scene.objects.active = obj
    obj.select = True

    #while True:
        #if obj.select == 'True' and scene.objects.active == obj:

bpy.utils.register_class(OPA)  
$\endgroup$
1
$\begingroup$

Your operator does nothing. It's missing an execute or invoke function.

To do what you want to do, you could create a modal operator:

  1. In its invoke function you would create a circle curve object.
  2. In it's modal function you would change the U resolution of the curve and the scale, for instance based on mouse movement
  3. when confirming the modal, you would convert the curve to a mesh (if that is what you want)

Check the template scripts in Blender to understand how operators are structured.

$\endgroup$
  • $\begingroup$ Thank you! I tried piemenus editor to create modal operator. I cant use curve circle, cause the U only power of 2, i need odd number of vertices too. Is there way to update bmesh, but retain loc rot scale $\endgroup$ – youthatninja Mar 20 at 14:38

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.