am trying to create a solid wall mesh as like in 3ds max.
from bpy.props import FloatProperty
class wall_panel(bpy.types.Panel):
bl_label = "Solid Wall Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
# Following part of the pane is not working
obj = bpy.context.active_object
row = layout.row()
row.prop(obj, "length")
row = layout.row()
row.prop(obj, "height")
class Wall(bpy.types.Operator):
bl_idname = "Wall"
bl_label = "Solid Wall"
bl_description = "Wall"
length = FloatProperty(name = "Length",attr = "length",
description="Length of the wall",
default = 2.0, min = 0.01, max = 100.0)
width = FloatProperty(name = "Width",attr = "width",
description="Width of the wall",
default = 0.5, min = 0.01, max = 100.0)
height = FloatProperty(name = "Height",attr = "height",
description="Height of the wall",
default = 1.0, min = 0.01, max = 100.0)
def invoke(self, context, event):
l = self.properties.length
w = self.properties.width
h = self.properties.height
v = [(-l-w,-h,-w/2),(-l,-h,-w/2),(l,-h,-w/2),(l+w,-h,-w/2),(l+w,h,-w/2),(l,h,-w/2),(-l,h,-w/2),(-l-w,h,-w/2),(-l-w,-h,w/2),(-l,-h,w/2),(l,-h,w/2),(l+w,-h,w/2),(l+w,h,w/2),(l,h,w/2),(-l,h,w/2),(-l-w,h,w/2)]
faces = [[0,1,6,7],[0,8,15,7],[0,1,9,8],[14,15,8,9],[14,15,7,6],[14,6,1,9],[14,13,10,9],[14,13,5,6],[2,5,6,1],[2,5,13,10],[2,10,9,1],[2,3,4,5],[2,3,11,10],[12,13,10,11],[12,13,5,4],[12,4,3,11]]
for ob in bpy.context.scene.objects:
ob.selected = False
mesh = bpy.data.meshes.new("Wall")
mesh.from_pydata(v,[],faces)
mesh.update()
ob = bpy.data.objects.new("Wall", mesh)
bpy.context.scene.objects.link(ob)
ob.selected = True
ob.location = bpy.context.scene.cursor_location
bpy.scene.objects.active = ob # not working
#bpy.ops.object.editmode_toggle()
return{'FINISHED'}
bpy.types.register(wall_panel)
bpy.types.register(Wall)
menu_func = (lambda self, context: self.layout.operator('Wall'))
bpy.types.INFO_MT_mesh_add.append(menu_func)
I have some problems with this script
- After inserting the mesh the object is selected but not getting activated. I tried scene.objects.active = ob but it is not working
- i need to change the wall parameter values (length, width and height) by using the panel. but in panel nothing showing.
can any one help me on this