1
$\begingroup$

Anybody has an idea what the python code is to draw the edge data bevel and crease weight sliders?

enter image description here

It seems not to be part of "space_view3d.py"

$\endgroup$
2
  • $\begingroup$ not sure why this was downvoted, but this submenu is defined in C, not python -- (you can see this by rightclicking any of the sliders and trying to edit-source). I think you'll have to do a little bit of coding :) $\endgroup$
    – zeffii
    Commented Jan 11, 2016 at 20:29
  • $\begingroup$ Thats the impression I got as well. Is it possible to write a script that shows a slider and the value is uses as for edge crease or bevel weight? I found the commands that adjust the edge data and the thing that might store the data? bpy.types.MeshEdge bpy.ops.transform.edge_bevelweight(value=0.366871) bpy.ops.transform.edge_crease(value=-0.315626) $\endgroup$ Commented Jan 11, 2016 at 20:33

1 Answer 1

7
$\begingroup$

EDITED:

OK, apparently the previous answer was pretty worthless. Although there is a meshedge.crease property and a meshvertex.bevel_weight property, they do not influence modifiers at all, and their values do not change when changing the corresponding values in the properties panel.

However, there is a way to access these values through custom layers via BMESH. The addon below adds a panel that allows you to influence selected verts / edges or all verts / edges' crease and bevel weight properties.

enter image description here

It does have one weird bug though, which seems to be a bug in Blender, as seen in the GIF above. Even though this does indeed update the respective mesh properites, Blender does not update the display until you also change any value of a modifier on the active mesh.

EDITED 2:

Thanks to a comment from batFINGER, found a solution to the weird behavior mentioned and seen above: adding a bmesh.update_edit_mesh( meshData ) after updating the crease / bevel values. Updated code below accordingly.

To use this, download the code and save it as a python (.py) file on your computer, then install it as an addon (File --> User Preferences --> Add-ons --> Install From File).

The panel appears in Edit Mode only in the Tools tab, under "Crease and Bevel".

bl_info = {
    "name"       : "Crease and Bevel weight panel",
    "version"    : (0, 0, 1),
    "blender"    : (2, 77, 0),
    "category"   : "Tools",
    "location"   : "3D View > Toolbox",
    "description": "Shortcut UI panel for Mesh edge crease and vertex bevel weight properties"
}

import bpy, bmesh

class creaseAndBevelPanel(bpy.types.Panel):
    bl_idname      = "creaseAndBevelPanel"
    bl_label       = "Crease and Bevel"
    bl_space_type  = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_category    = 'Tools'
    bl_context     = "mesh_edit"

    @classmethod
    def poll( self, context ):
        ''' Only show panel if there is an active mesh object '''
        return context.object and context.object.type == 'MESH'

    def draw( self, context ):
            layout = self.layout
            props  = context.scene.creaseAndBevelPG # Create reference to property group

            box = layout.box()                    # Draw a box
            col = box.column( align = True )      # Create a column
            col.prop( props, "whoToInfluence"  )  # Add properites to panel
            col.prop( props, "bevelWeight"     )
            col.prop( props, "edgeCrease"      )

class creaseAndBevelPG(bpy.types.PropertyGroup):
    ## Update functions
    def update_bevelWeight( self, context ):
        ''' Update function for bevelWeight property '''

        o  = bpy.context.object
        d  = o.data
        bm = bmesh.from_edit_mesh( d )

        bevelWeightLayer = bm.verts.layers.bevel_weight['BevelWeight']

        if self.whoToInfluence == 'Selected Elements':
            selectedVerts = [ v for v in bm.verts if v.select ]
            for v in selectedVerts: v[ bevelWeightLayer ] = self.bevelWeight
        else:
            for v in bm.verts: v[ bevelWeightLayer ] = self.bevelWeight

        bmesh.update_edit_mesh( d )

    def update_edgeCrease( self, context ):
        ''' Update function for edgeCrease property '''

        o  = bpy.context.object
        d  = o.data
        bm = bmesh.from_edit_mesh( d )

        creaseLayer = bm.edges.layers.crease['SubSurfCrease']

        if self.whoToInfluence == 'Selected Elements':
            selectedEdges = [ e for e in bm.edges if e.select ]
            for e in selectedEdges: e[ creaseLayer ] = self.edgeCrease
        else:
            for e in bm.edges: e[ creaseLayer ] = self.edgeCrease

        bmesh.update_edit_mesh( d )

    ## Properties
    items = [
        ('All', 'All', ''),
        ('Selected Elements', 'Selected Elements', '')
    ]

    whoToInfluence = bpy.props.EnumProperty( # Material distribution method
        description = "Influence all / selection",
        name        = "whoToInfluence",
        items       = items,
        default     = 'Selected Elements'
    )

    bevelWeight = bpy.props.FloatProperty(
        description = "Bevel Weight",
        name        = "bevelWeight",
        min         = 0.0,
        max         = 1.0,
        step        = 0.01,
        default     = 0,
        update      = update_bevelWeight
    )

    edgeCrease = bpy.props.FloatProperty(
        description = "Edge Crease",
        name        = "edgeCrease",
        min         = 0.0,
        max         = 1.0,
        step        = 0.01,
        default     = 0,
        update      = update_edgeCrease
    )

def register():
    bpy.utils.register_module(__name__)
    bpy.types.Scene.creaseAndBevelPG = bpy.props.PointerProperty( type = creaseAndBevelPG )

def unregister():
    bpy.utils.unregister_module(__name__)
$\endgroup$
16
  • 1
    $\begingroup$ @Tiles, see updated answer. $\endgroup$
    – TLousky
    Commented Aug 14, 2016 at 11:08
  • 1
    $\begingroup$ Tried all kinds of redraws and updates (context.scene.update(), object.modifiers.update() and the tag_redraw function), nothing really works. It's really weird since usually, when you move the 3D view the scene is redrawn and everything is updated, but in this case I found that only changing a modifier's property did the trick. $\endgroup$
    – TLousky
    Commented Aug 14, 2016 at 12:09
  • 1
    $\begingroup$ Too bad. Nevertheless thanks for your investigation and help :) $\endgroup$
    – Tiles
    Commented Aug 14, 2016 at 16:00
  • 3
    $\begingroup$ How about a bmesh.update_edit_mesh(d) at end of update method? quick test looks good for edge crease.... $\endgroup$
    – batFINGER
    Commented Aug 15, 2016 at 8:16
  • 1
    $\begingroup$ Awesome @batFINGER, works like a charm, will update answer. $\endgroup$
    – TLousky
    Commented Aug 15, 2016 at 8:38

You must log in to answer this question.

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