Branch Extrusion

Hi guys, this is my first Add -ons: Branch Extrusion.

This Add -ons make extrusion and resizing a Face by following the mouse path, like you are drawing.

you can change the distance between to faces(min distance from 0 to 999), and the resize value (taper value, from 0 to 999).
You can set the orientation(NORMAL, LOCAL, GLOBAL) and the constrained axis(x, y, z).

The script add a user interface in the mesh tool.
For get the script work simply click on the relative button and by holding the LMB move the mouse on the place where you want the next face. To confirm use RMB

this is the add - on

version 1.45
Branch_Extrusion_Bmesh 1_45.zip (3.51 KB)

some bugfix

tell me if you like it, report any bug, issues or improvement here

ps: special thanks to batFINGER and all the blenderartists community for the help

Attachments


Quick note

need to get rid of that breakpoint line

#breakpoint = bpy.types.bp.bp

also my version of blender is spitting the dummy at line 111 cos it doesn’t like the faces collection… looks like it’s polygons now.
IMO a couple of quick changes and you could convert this to bmesh and avoid the mode flipping.

i’ve to do this to update all the variables, if there is another way i don’t know… i just start to program 3 weeks ago and i never used python or other language aprt turbo pascal some years ago :smiley:

for the blender version i’ve the official 2.62 i’ll try to change this thing…

cool script! I have to try :smiley:

thankyou!

quickly tried it out at lunch. cool script…can see potential for it. Could not get the geometry to follow the direction of the mouse movement. I tried adding a line of code (don’t know enough about ‘live code’), but could not get it to work, so I thought I’ll check with you.

if you added the line:

bpy.ops.mesh.dupli_extrude_cursor(rotate_source=True)

…rather than doing the whole code, then shouldn’t that give the wanted result? did not want to work with me, but had very little time to try.
(That line is the same as holding CTRL + RMB and clicking…and then changes the rotation of the previous duplication.)

i look at it and you are right it don’t follow the mouse “orientation” maybe i can try to adjust this. another bug i’ve found is that it don’t work in ortho view, so if you are in ortho go in prospective view. for the dupli extrude, with this you don’t have control on the orientation and other parameters i think, so for the moment i use the normal extrusion ops… thank for the suggestion i’ll work on it, maybe it work better, otherwise if you have any issues, ask me! :smiley:

ok…fixed the code. works in bmesh now. still not sure how to do the rotation?


 ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####


bl_info = {
    "name": "Branch Extrusion",
    "author": "Rebellion",
    "version": (1, 0),
    "blender": (2, 6, 2),
    "location": "View3D > Object_Edit > Mesh Tools ",
    "description": "Extrude and Resize the face",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Mesh"}


#set the next face to the set distance (min distance)
#set the taper value = difference between the first and next face

##########
# import
##########
import bpy, mathutils
import bmesh
from bpy.props import IntProperty, FloatProperty
from bpy_extras.view3d_utils import region_2d_to_vector_3d, region_2d_to_location_3d



def extrusion(coord,region,rv3d,vec,loc,face,face_center,taper_value, cons_x,cons_y,cons_z,orientation):
    
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.ops.object.mode_set(mode='EDIT')
    
    # extrude face(s)   
    bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False}, TRANSFORM_OT_translate={"value":(loc), "constraint_axis":(cons_x, cons_y, cons_z), "constraint_orientation": orientation})
    bpy.ops.transform.translate(value =(-face_center ), constraint_axis=(cons_x, cons_y, cons_z))         
    
    bpy.ops.transform.resize(value = (taper_value, taper_value, taper_value)) # to set manually
    
        
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.ops.object.mode_set(mode='EDIT')

class BranchExtrusionOperator(bpy.types.Operator):
    
  
    bl_idname = "object.branch_extrusion"
    bl_label = "Branch Extrusion"
    bl_options = {'REGISTER', 'UNDO'}
    
    bpy.types.Scene.min_distance = FloatProperty(name='Min Distance', min=0, max=999, soft_min=0, \
        soft_max=20, default= 5, description='Minimun distance from a face to another')
    
    bpy.types.Scene.taper_value = bpy.props.FloatProperty(name= 'Taper Value', min=0, max=999, soft_min=0.001, \
        soft_max=2, default= 0.5, description='Difference in size from a face to another')
    
    bpy.types.Scene.cons_x = bpy.props.BoolProperty(name= 'X Axis', default = False)
    bpy.types.Scene.cons_y = bpy.props.BoolProperty(name= 'Y Axis', default = False)
    bpy.types.Scene.cons_z = bpy.props.BoolProperty(name= 'Z Axis', default = False)
    bpy.types.Scene.orientation = bpy.props.EnumProperty(items = [( 'GLOBAL','Global','Global'), ('LOCAL','Local','Normal'), ('NORMAL','Normal','Local')],name = "")

    
    
    # create scene variables
    bpy.context.scene.min_distance = 5
    bpy.context.scene.taper_value = 0.5
    bpy.context.scene.cons_x = False
    bpy.context.scene.cons_y = False
    bpy.context.scene.cons_z = False
    bpy.context.scene['orientation'] = 1
    
    
    LMB_Hold = False

    def modal(self, context, event):
                  
        if event.type == 'MOUSEMOVE' and self.LMB_Hold:
        
            bpy.ops.object.mode_set(mode='OBJECT')
            bpy.ops.object.mode_set(mode='EDIT')
            
            # create variables           
            coord = event.mouse_region_x, event.mouse_region_y
            region = context.region
            rv3d = context.space_data.region_3d
            vec = region_2d_to_vector_3d(region, rv3d, coord)
            loc = (region_2d_to_location_3d(region, rv3d, coord, vec))
            print (loc/30)
            
            # get face center
            bpy.ops.object.mode_set(mode='OBJECT')
            me = bpy.context.object.data # Get the active mesh
            bm = bmesh.new()   # create an empty BMesh
            bm.from_mesh(me)   # fill it in from a Mesh
            face = bpy.context.object.data.faces.active
            face_center = bm.faces[face].calc_center_bounds()
            bpy.ops.object.mode_set(mode='EDIT')
            
            increment = round( mathutils.Vector((loc - face_center)).length, 0) 
            
            scn = context.scene     
            
                 
            if increment >= scn['min_distance']:
               extrusion(coord,region,rv3d,vec,loc,face,face_center,scn['taper_value'],scn.cons_x ,scn.cons_y,scn.cons_z,scn.orientation)
                        
        elif event.type == 'LEFTMOUSE':
            if event.value == 'PRESS':
                self.LMB_Hold = True
            elif event.value == 'RELEASE':
                self.LMB_Hold = False
     
            
        elif event.type in {'RIGHTMOUSE', 'NUMPAD_ENTER'}:
           
            return {'FINISHED'}
        
        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        if context.object:
            context.window_manager.modal_handler_add(self)
            
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "No active object, could not finish")
            return {'CANCELLED'}
    
        
    
        
class UI (bpy.types.Panel):
    bl_label = 'Branch Extrusion'
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = "mesh_edit"
   
   

    def draw(self, context):
        
        scn = context.scene 
             
        layout = self.layout
        column = layout.column(align=True)
        column.operator('object.branch_extrusion')  
        column.label(text='Extrusion set:')
        column.prop(scn,'min_distance' , slider=True)
        column.prop(scn, 'taper_value', slider=True) 
        column.label(text='Constraint_axis')
        column.prop(scn,'cons_x')   
        column.prop(scn,'cons_y') 
        column.prop(scn,'cons_z') 
        column.label(text='ORIENTATION')
        column.prop(scn,'orientation')   
            


def Menu_append(self, context):
    self.layout.separator()
    self.layout.operator(BranchExtrusionOperator.bl_idname, text="Branch Extrusion")
 

def register():
    bpy.utils.register_class(BranchExtrusionOperator)
    #bpy.types.VIEW3D_MT_edit_mesh_normals.append(Menu_append)
    #bpy.types.VIEW3D_PT_tools_meshedit_options.append(UI)
    bpy.utils.register_class(UI)
    
def unregister():
    bpy.utils.unregister_class(BranchExtrusionOperator)
    bpy.types.VIEW3D_MT_edit_mesh_normals.remove(Menu_append)
    bpy.utils.unregister_class(UI)
    
if __name__ == "__main__":
    register()

unfortunaly no… and at the moment i’ve enough time, this afternnon i’ll try your bmesh version and i’ll do a quick change to improve it. the next thing i want to do is add an option that make the branches end with one single verts, and an option to auto rotate, like you suggest(how??). maybe if a snip a the dupli extrude code, i’ll found the way to do it!

Hallo, in the Blender compiled yesterday there where some small changes needed.
From a ‘mesh’ you should use the polygons and not the faces .
Changing line 112 to face = bpy.context.object.data.polygons.active
it works

Attachments


yes i know, tomorrow, maybe, i’ll release the 1.1 version for both bmesh and old modeling system!

Forgotton???

YOUR bmesh version will not work!
face = bpy.context.object.data.faces.active will not show a good index (error even!)

AttributeError: ‘Mesh’ object has no attribute ‘faces’

REPLACE by
face = bpy.context.object.data.polygons.active
And note in the console one has to switch from edit to object to edit mode to see the selected face. In the script this seems not to be needed.

sorry :stuck_out_tongue: you’r right i fix it, I’ve substitute the precedent attachment

no problem at all, it is so easy to make a (small) mistake :wink:

for the next release i’ll put two more features

spin face: spin the face during the edting to make a torsion that affect all the branch
auto rotate: that rotate initial selection to giving better shape

if some one have other request ask me!

Version 1,3

which one did you update? I tried the bmesh one and it doesn’t work?

sorry, little mistake, i’m working on the two script at the same time and i forgot to change face in polygons in the script…

sorry, little mistake, i’m working on the two script at the same time and i forgot to change face in polygons in the script…
so now i change the attachment :stuck_out_tongue:

Are all the updates that you made included in the two zip files that you give links to in this first post of this thread?

yes, the old file are no more available, each time i made an update i have change the attachment directly so on the add-on panel the user i always directed to the first post