HAlpha
(HAlpha)
August 28, 2014, 7:36am
1
Hi all,
I am trying to customize the UI of blender in order to simplify it.
I don’t need all the commands, and I usually work with mesh, deformation tools and sculpting.
The only command I need is the Remesh modifier and i must access to the properties panel to run it just once before the sculpting.
I work with a single object every time.
The commands are:
bpy.ops.object.modifier_add(type=‘REMESH’)
bpy.context.object.modifiers[“Remesh”].octree_depth = 7
bpy.context.object.modifiers[“Remesh”].mode = ‘SMOOTH’
bpy.context.object.modifiers[“Remesh”].scale = 0.99
bpy.context.object.modifiers[“Remesh”].use_smooth_shade = True
bpy.ops.object.modifier_apply(apply_as=‘DATA’, modifier=“Remesh”)
I would like to create a custom button on the transform panel of the 3D environment that calls these commands…
I’ve tried to write my own code, creating a class, editing the 3D view panell etc. but I failed…
Any suggestion/help?
Tnx!
CoDEmanX
(CoDEmanX)
August 28, 2014, 6:35pm
2
bl_info = {
"name": "Remesh Apply",
"author": "CoDEmanX",
"version": (1, 0),
"blender": (2, 65, 0),
"location": "Properties > Object > Transform",
"description": "Add Remesh modifier and apply",
"warning": "",
"wiki_url": "",
"category": "Object"}
import bpy
from bpy.types import Operator
def draw_func(self, context):
layout = self.layout
layout.operator(OBJECT_OT_remesh_apply.bl_idname, icon='MOD_REMESH')
class OBJECT_OT_remesh_apply(Operator):
bl_idname = "object.remesh_apply"
bl_label = "Add Remesh modifier and apply"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.object is not None and context.object.type == 'MESH'
def execute(self, context):
ob = context.object
mod = ob.modifiers.new("", 'REMESH')
mod.octree_depth = 7
mod.mode = 'SMOOTH'
mod.scale = 0.99
mod.use_smooth_shade = True
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=mod.name)
# You might want to use this instead...
#ob.to_mesh()
return {'FINISHED'}
def register():
bpy.utils.register_module(__name__)
bpy.types.OBJECT_PT_transform.append(draw_func)
def unregister():
bpy.utils.register_module(__name__)
bpy.types.OBJECT_PT_transform.remove(draw_func)
if __name__ == "__main__":
register()
Save that to a .py file and install as addon, then enable.
HAlpha
(HAlpha)
August 29, 2014, 2:11am
3
Thank you very very much!
You’ve made my day!
I’m a programmer but I am a newbie in python
This will also help me for further scripts!!
[SOLVED]
HAlpha
(HAlpha)
August 29, 2014, 6:08am
4
Your code works perfectly!
may I ask why insted this one does not work?
I tried to edit it but the result is not completely correct…
import bpy
from bpy.types import Operator
def draw_func(self, context):
layout = self.layout
layout.operator(OBJECT_OT_tomesh_apply.bl_idname, icon=‘Mesh_Mode’)
class OBJECT_OT_tomesh_apply(Operator):
bl_idname = “object.mesh_mode”
bl_label = “Start Mesh Mode”
bl_options = {‘REGISTER’, ‘UNDO’}
@classmethod
def poll(cls, context):
return context.object is not None and context.object.type == 'MESH'
def execute(self, context):
ob = context.object
bpy.ops.object.editmode_toggle()
bpy.context.space_data.viewport_shade = 'WIREFRAME'
bpy.ops.mesh.select_all(action='TOGGLE')
return {'FINISHED'}
def register():
bpy.utils.register_module(name )
bpy.types.OBJECT_PT_transform.append(draw_func)
def unregister():
bpy.utils.register_module(name )
bpy.types.OBJECT_PT_transform.remove(draw_func)
if name == “main ”:
register()
if I run it from the menu it works… but i cannot link it into a button…
CoDEmanX
(CoDEmanX)
August 29, 2014, 2:44pm
5
‘Mesh_Mode’ is not an icon, and because you run the operator from the properties editor, there is no viewport_shade in the that space.
import bpy
from bpy.types import Operator
def draw_func(self, context):
layout = self.layout
layout.operator(OBJECT_OT_mesh_mode.bl_idname, icon='EDITMODE_HLT')
class OBJECT_OT_mesh_mode(Operator):
bl_idname = "object.mesh_mode"
bl_label = "Start Mesh Mode"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.object is not None and context.object.type == 'MESH'
def execute(self, context):
ob = context.object
bpy.ops.object.editmode_toggle()
for area in context.screen.areas:
if area.type == 'VIEW_3D':
area.spaces.active.viewport_shade = 'WIREFRAME'
bpy.ops.mesh.select_all(action='TOGGLE')
return {'FINISHED'}
def register():
bpy.utils.register_module(__name__)
bpy.types.OBJECT_PT_transform.append(draw_func)
def unregister():
bpy.utils.register_module(__name__)
bpy.types.OBJECT_PT_transform.remove(draw_func)
if __name__ == "__main__":
register()