Page Menu
Home
Search
Configure Global Search
Log In
Files
F26610
quickaccess_menu.py
Public
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Warren Taylor (blender_geek)
Nov 13 2013, 5:35 PM
Size
13 KB
Subscribers
None
quickaccess_menu.py
View Options
### 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"
:
"QuickAccess Menu"
,
"description"
:
"An easy access menu for several useful scripts realated to mesh modeling."
,
"author"
:
"Warren Taylor"
,
"version"
:
(
1
,
0
),
"blender"
:
(
2
,
64
,
0
),
"location"
:
"View3D > Tools > QuickAccess Menu"
,
"warning"
:
"Stable but has a few bugs"
,
"wiki_url"
:
"http://www.blender.org/"
,
"tracker_url"
:
"http://www.facebook.com/warren.x.taylor"
,
"category"
:
"3D View"
}
import
bpy
from
bpy.props
import
*
#define operations
quickAccess_RAD
=
'Remove All Doubles'
quickAccess_TDSN
=
'Toggle Double Sided Normals'
quickAccess_FN
=
'Flip Normals'
quickAccess_RN
=
'Recalculate Normals'
quickAccess_SS
=
'Smooth Shading'
quickAccess_FS
=
'Flat Shading'
quickAccess_SUB
=
'Subdivide'
#quickAccess_SM = 'Sculpt Mode'
#--------------------------------------------------------------------------
#define global properties
#--------------------------------------------------------------------------
#RemoveDoubles properties
RemoveDoubles_Dist
=
0.0025
#RecalculateNormals properties
RecalculateNormals_Inside
=
False
#Subdivide properties
Subdivide_NCuts
=
1
Subdivide_Smoothness
=
0.0
Subdivide_QuadTri
=
False
Subdivide_QuadCorner
=
'STRAIGHT_CUT'
Subdivide_Fractal
=
0
Subdivide_Normal
=
0
Subdivide_Seed
=
0
# QuickAccess Panel
class
QuickAccessPanel
(
bpy
.
types
.
Panel
)
:
bl_label
=
"QuickAccess Menu"
bl_idname
=
"OBJECT_MT_QuickAccessMenu"
bl_space_type
=
"VIEW_3D"
bl_region_type
=
"TOOLS"
def
draw
(
self
,
context
)
:
layout
=
self
.
layout
layout
.
label
(
"Verts"
)
layout
.
operator
(
"quickaccess.rad"
,
text
=
quickAccess_RAD
)
layout
.
operator
(
"quickaccess.sub"
,
text
=
quickAccess_SUB
)
layout
.
label
(
"Normals"
)
layout
.
operator
(
"quickaccess.tdsn"
,
text
=
quickAccess_TDSN
)
layout
.
operator
(
"quickaccess.rn"
,
text
=
quickAccess_RN
)
layout
.
operator
(
"quickaccess.fn"
,
text
=
quickAccess_FN
)
layout
.
label
(
"Shading"
)
layout
.
operator
(
"quickaccess.ss"
,
text
=
quickAccess_SS
)
layout
.
operator
(
"quickaccess.fs"
,
text
=
quickAccess_FS
)
# layout.label( "Other" )
# layout.operator( "quickaccess.sm", text = quickAccess_SM )
layout
.
separator
()
class
QuickAccess_RemoveAllDoubles
(
bpy
.
types
.
Operator
)
:
"""Remove all doubles (even unselected ones) for the active mesh object."""
bl_idname
=
"quickaccess.rad"
bl_label
=
"Remove All Doubles"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
merDist
=
FloatProperty
(
name
=
"Merge Distance"
,
description
=
"Distance between elements to merge"
,
default
=
0.0025
,
min
=
0.00001
,
max
=
10
)
def
execute
(
self
,
context
)
:
obj
=
bpy
.
context
.
active_object
if
obj
.
type
==
'MESH'
:
bpy
.
ops
.
object
.
mode_set
(
mode
=
'EDIT'
)
bpy
.
ops
.
mesh
.
select_all
(
action
=
'SELECT'
)
bpy
.
ops
.
mesh
.
remove_doubles
(
threshold
=
self
.
merDist
)
bpy
.
ops
.
object
.
mode_set
(
mode
=
'OBJECT'
)
else
:
message
=
"WARNING: |The active object is not of 'mesh' type!"
self
.
report
(
{
'WARNING'
},
message
)
print
(
message
)
return
{
'FINISHED'
}
def
invoke
(
self
,
context
,
event
)
:
global
RemoveDoubles_Dist
self
.
merDist
=
RemoveDoubles_Dist
return
context
.
window_manager
.
invoke_props_dialog
(
self
)
class
QuickAccess_ToggleDoubleSidedNormals
(
bpy
.
types
.
Operator
)
:
"""Toggles between single and double sided normals for the active mesh object."""
bl_idname
=
"quickaccess.tdsn"
bl_label
=
"Double Sided Normals"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
def
execute
(
self
,
context
)
:
obj
=
bpy
.
context
.
active_object
if
obj
.
type
==
'MESH'
:
if
obj
.
data
.
show_double_sided
==
True
:
message
=
"Double Sided Normals: |Off"
obj
.
data
.
show_double_sided
=
False
self
.
report
(
{
'INFO'
},
message
)
print
(
message
)
else
:
message
=
"Double Sided Normals: |On"
obj
.
data
.
show_double_sided
=
True
self
.
report
(
{
'INFO'
},
message
)
print
(
message
)
else
:
message
=
"WARNING: |The active object is not of 'mesh' type!"
self
.
report
(
{
'WARNING'
},
message
)
print
(
message
)
return
{
'FINISHED'
}
class
QuickAccess_FlipNormals
(
bpy
.
types
.
Operator
)
:
"""Flip the direction of the normals for the active mesh object."""
bl_idname
=
"quickaccess.fn"
bl_label
=
"Flip Normals"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
def
execute
(
self
,
context
)
:
obj
=
bpy
.
context
.
active_object
if
obj
.
type
==
'MESH'
:
bpy
.
ops
.
object
.
mode_set
(
mode
=
'EDIT'
)
bpy
.
ops
.
mesh
.
select_all
(
action
=
'SELECT'
)
bpy
.
ops
.
mesh
.
flip_normals
()
bpy
.
ops
.
object
.
mode_set
(
mode
=
'OBJECT'
)
else
:
message
=
"WARNING: |The active object is not of 'mesh' type!"
self
.
report
(
{
'WARNING'
},
message
)
print
(
message
)
return
{
'FINISHED'
}
class
QuickAccess_RecalculateNormals
(
bpy
.
types
.
Operator
)
:
"""Recalculate all normals for the active mesh object."""
bl_idname
=
"quickaccess.rn"
bl_label
=
"Recalculate Normals"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
inside
=
BoolProperty
(
name
=
"Inside"
,
default
=
False
)
def
execute
(
self
,
context
)
:
obj
=
bpy
.
context
.
active_object
if
obj
.
type
==
'MESH'
:
bpy
.
ops
.
object
.
mode_set
(
mode
=
'EDIT'
)
bpy
.
ops
.
mesh
.
select_all
(
action
=
'SELECT'
)
bpy
.
ops
.
mesh
.
normals_make_consistent
(
inside
=
self
.
inside
)
bpy
.
ops
.
object
.
mode_set
(
mode
=
'OBJECT'
)
else
:
message
=
"WARNING: |The active object is not of 'mesh' type!"
self
.
report
(
{
'WARNING'
},
message
)
print
(
message
)
return
{
'FINISHED'
}
def
invoke
(
self
,
context
,
event
)
:
global
RecalculateNormals_Inside
self
.
inside
=
RecalculateNormals_Inside
return
context
.
window_manager
.
invoke_props_dialog
(
self
)
class
QuickAccess_SmoothShading
(
bpy
.
types
.
Operator
)
:
"""Set the shading of the active mesh object to smooth."""
bl_idname
=
"quickaccess.ss"
bl_label
=
"Smooth Shading"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
def
execute
(
self
,
context
)
:
obj
=
bpy
.
context
.
active_object
if
obj
.
type
==
'MESH'
:
bpy
.
ops
.
object
.
mode_set
(
mode
=
'OBJECT'
)
bpy
.
ops
.
object
.
shade_smooth
()
else
:
message
=
"WARNING: |The active object is not of 'mesh' type!"
self
.
report
(
{
'WARNING'
},
message
)
print
(
message
)
return
{
'FINISHED'
}
class
QuickAccess_FlatShading
(
bpy
.
types
.
Operator
)
:
"""Set the shading of the active mesh object to flat."""
bl_idname
=
"quickaccess.fs"
bl_label
=
"Flat Shading"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
def
execute
(
self
,
context
)
:
obj
=
bpy
.
context
.
active_object
if
obj
.
type
==
'MESH'
:
bpy
.
ops
.
object
.
mode_set
(
mode
=
'OBJECT'
)
bpy
.
ops
.
object
.
shade_flat
()
else
:
message
=
"WARNING: |The active object is not of 'mesh' type!"
self
.
report
(
{
'WARNING'
},
message
)
print
(
message
)
return
{
'FINISHED'
}
class
QuickAccess_Subdivide
(
bpy
.
types
.
Operator
)
:
"""Subdivide the selected edges of the active mesh object."""
bl_idname
=
"quickaccess.sub"
bl_label
=
"Subdivide Edges"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
nCuts
=
IntProperty
(
name
=
"Number of Cuts"
,
default
=
1
,
min
=
1
,
max
=
10
)
smoothness
=
FloatProperty
(
name
=
"Smoothness"
,
description
=
"Smoothness factor"
,
default
=
0
,
min
=
0
,
max
=
1
)
quadTri
=
BoolProperty
(
name
=
"Quad/Tri Mode"
,
description
=
"Tries to prevent ngons"
,
default
=
False
)
quadCorner
=
EnumProperty
(
name
=
"Quad Corner Type"
,
description
=
"How to subdivide quad corners (anything other than Straight Cut will prevent ngons)"
,
items
=
[
(
'INNERVERT'
,
'Inner Vert'
,
''
),
(
'PATH'
,
'Path'
,
''
),
(
'STRAIGHT_CUT'
,
'Straight Cut'
,
''
),
(
'FAN'
,
'Fan'
,
''
)
],
default
=
'STRAIGHT_CUT'
)
fractal
=
FloatProperty
(
name
=
"Fractal"
,
description
=
"Fractal randomness factor"
,
default
=
0
,
min
=
0
,
max
=
1000
)
normal
=
FloatProperty
(
name
=
"Along Normal"
,
description
=
"Apply fractal displasement along normal only"
,
default
=
0
,
min
=
0
,
max
=
1
)
seed
=
IntProperty
(
name
=
"Seed"
,
description
=
"Seed for random number generator"
,
default
=
0
,
min
=
0
,
max
=
50
)
def
execute
(
self
,
context
)
:
obj
=
bpy
.
context
.
active_object
if
obj
.
type
==
'MESH'
:
bpy
.
ops
.
object
.
mode_set
(
mode
=
'EDIT'
)
bpy
.
ops
.
mesh
.
subdivide
(
number_cuts
=
self
.
nCuts
,
smoothness
=
self
.
smoothness
,
quadtri
=
self
.
quadTri
,
quadcorner
=
self
.
quadCorner
,
fractal
=
self
.
fractal
,
fractal_along_normal
=
self
.
normal
,
seed
=
self
.
seed
)
else
:
message
=
"WARNING: |The active object is not of 'mesh' type!"
self
.
report
(
{
'WARNING'
},
message
)
print
(
message
)
return
{
'FINISHED'
}
def
invoke
(
self
,
context
,
event
)
:
global
Subdivide_NCuts
,
Subdivide_Smoothness
self
.
nCuts
=
Subdivide_NCuts
self
.
_smoothness
=
Subdivide_Smoothness
self
.
quadCorner
=
Subdivide_QuadCorner
self
.
fractal
=
Subdivide_Fractal
return
context
.
window_manager
.
invoke_props_dialog
(
self
)
#class QuickAccess_SculptMode( bpy.types.Operator ) :
# """Switch to Sculpt Mode for the active mesh object."""
# bl_idname = "quickaccess.sm"
# bl_label = "Toggle Sculpt Mode"
# bl_options = { 'REGISTER', 'UNDO' }
# def execute( self, context ) :
# obj = bpy.context.active_object
# if obj.type == 'MESH' :
# bpy.ops.object.mode_set( mode = 'OBJECT' )
# bpy.ops.sculpt.sculptmode_toggle()
# else :
# message = "WARNING: |The active object is not of 'mesh' type!"
# self.report( { 'WARNING' }, message )
# print( message )
# return { 'FINISHED' }
class
QuickAccessMenu
(
bpy
.
types
.
Menu
)
:
bl_label
=
"QuickAccess Menu"
bl_idname
=
"OBJECT_MT_quickAccessMenu"
def
draw
(
self
,
context
)
:
layout
=
self
.
layout
layout
.
label
(
"Verts"
)
layout
.
operator
(
"quickaccess.rad"
,
text
=
quickAccess_RAD
)
layout
.
operator
(
"quickaccess.sub"
,
text
=
quickAccess_SUB
)
layout
.
label
(
"Normals"
)
layout
.
operator
(
"quickaccess.tdsn"
,
text
=
quickAccess_TDSN
)
layout
.
operator
(
"quickaccess.rn"
,
text
=
quickAccess_RN
)
layout
.
operator
(
"quickaccess.fn"
,
text
=
quickAccess_FN
)
layout
.
label
(
"Shading"
)
layout
.
operator
(
"quickaccess.ss"
,
text
=
quickAccess_SS
)
layout
.
operator
(
"quickaccess.fs"
,
text
=
quickAccess_FS
)
# layout.label( "Other" )
# layout.operator( "quickaccess.sm", text = quickAccess_SM )
layout
.
separator
()
keymap
=
bpy
.
context
.
window_manager
.
keyconfigs
.
default
.
keymaps
[
'3D View'
]
for
keymapi
in
keymap
.
keymap_items
:
if
keymapi
.
idname
==
"wm.call_menu"
and
keymapi
.
properties
.
name
==
"OBJECT_MT_quickAccessMenu"
:
keymap
.
keymap_items
.
remove
(
keymapi
)
keymapi
=
keymap
.
keymap_items
.
new
(
'wm.call_menu'
,
'Q'
,
'PRESS'
,
shift
=
True
)
keymapi
.
properties
.
name
=
"OBJECT_MT_quickAccessMenu"
# registering
def
register
()
:
bpy
.
utils
.
register_class
(
QuickAccess_RemoveAllDoubles
)
bpy
.
utils
.
register_class
(
QuickAccess_ToggleDoubleSidedNormals
)
bpy
.
utils
.
register_class
(
QuickAccess_FlipNormals
)
bpy
.
utils
.
register_class
(
QuickAccess_RecalculateNormals
)
bpy
.
utils
.
register_class
(
QuickAccess_SmoothShading
)
bpy
.
utils
.
register_class
(
QuickAccess_FlatShading
)
bpy
.
utils
.
register_class
(
QuickAccess_Subdivide
)
# bpy.utils.register_class( QuickAccess_SculptMode )
bpy
.
utils
.
register_class
(
QuickAccessMenu
)
bpy
.
utils
.
register_class
(
QuickAccessPanel
)
# unregistering
def
unregister
()
:
bpy
.
utils
.
unregister_class
(
QuickAccess_RemoveAllDoubles
)
bpy
.
utils
.
unregister_class
(
QuickAccess_ToggleDoubleSidedNormals
)
bpy
.
utils
.
unregister_class
(
QuickAccess_FlipNormals
)
bpy
.
utils
.
unregister_class
(
QuickAccess_RecalculateNormals
)
bpy
.
utils
.
unregister_class
(
QuickAccess_SmoothShading
)
bpy
.
utils
.
unregister_class
(
QuickAccess_FlatShading
)
bpy
.
utils
.
unregister_class
(
QuickAccess_Subdivide
)
# bpy.utils.unregister_class( QuickAccess_SculptMode )
bpy
.
utils
.
unregister_class
(
QuickAccessMenu
)
bpy
.
utils
.
unregister_class
(
QuickAccessPanel
)
if
__name__
==
"__main__"
:
register
()
File Metadata
Details
Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f0/79/de5abab4ed1df97d3ccd0b2c9d38
Event Timeline
Log In to Comment