mesh Generator

I create some what a simple mesh Generator still working on it. I added few menus in the tool panel on the left side. Show in object mode.

I was going to work on it more of it. But I got to work on other projects.

import bpy
import mathutils
from bpy.props import *
from mathutils import Vector
Vector = mathutils.Vector

buildingmodels = []
floors = []

sidepaneltype = []
sidepaneltype.append(("0","Front","front"))
sidepaneltype.append(("1","Back","back"))
sidepaneltype.append(("2","Right","right"))
sidepaneltype.append(("2","Left","left"))
sidepaneltype.append(("2","All","all"))

bpy.types.Scene.wallside = EnumProperty(
    name="Panel Side",
    description="",
    items = sidepaneltype, default = '0')
        
paneltype = []
paneltype.append(("0","Window","window"))
paneltype.append(("0","Door","door"))
paneltype.append(("0","Roof","roof"))
paneltype.append(("0","Ground","ground"))
    
bpy.types.Scene.buildingpaneltype = EnumProperty(
    name="Panel Type",
    description="",
    items = paneltype, default = '0')
    
bpy.types.Scene.cureentbuildingfloors = EnumProperty(
    name="Floors",
    description="",
    items = [],
    default = '0')

class Buildings(bpy.types.IDPropertyGroup):
    name = StringProperty(name="name", description="", maxlen=64, default="")
    
class BuildingsSettings(bpy.types.IDPropertyGroup):
    floors = CollectionProperty(type=Buildings, name="Floor List", description="")
    floors_index = IntProperty(name="Floor Index", description="", default=-1, min=-1, max=65535)
    
class floor:
    name = ""
    side = []
    verts = []
    faces = []
    
class VIEW3D_PT_BuildingGenerator(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_label = "Building Gen. Tool"
    
    meshname = "building" 
    objectname = "building" 
    
    bpy.types.Scene.buildingwidth = IntProperty(name="width", description="", default=1, min=0, max=300)
    bpy.types.Scene.buildinglength = IntProperty(name="length", description="", default=1, min=0, max=300)
    bpy.types.Scene.buildingheight = IntProperty(name="height", description="", default=1, min=0, max=300)    
    bpy.types.Scene.buildingwalls = IntProperty(name="Wall(s)", description="", default=1, min=1, max=300)
    bpy.types.Scene.buildingfloors = IntProperty(name="Floor(s)", description="", default=1, min=1, max=300)
    
    @classmethod
    def poll(cls, context):
        return context.active_object

    def draw(self, context):
        layout = self.layout
        scene = context.scene
        buildingstemplates = scene.buildingstemplates
        
        box1 = layout.box()
        box1.operator("object.BuiltBuilding")
        box1.operator("object.DestoryBuilding")
        
        for obj in bpy.data.objects:
            if obj.type == 'MESH' and obj.name == self.objectname:
                box2 = layout.box()
                box2.prop(scene,"buildingfloors")
                box2.operator("object.CreateBuildingFloors")
                                
                layout.template_list(buildingstemplates, "floors", buildingstemplates, "floors_index", rows=4)
                
                if buildingstemplates.floors_index > -1:
                
                    box4 = layout.box()
                    box4.prop(scene,"wallside")
                    box4.prop(scene,"buildingpaneltype")
                    box4.operator("object.CreatePanel")
                    box4.operator("object.CloneBuildingFloors")
                    box4.operator("object.RemoveFloor")
        
class OBJECT_OT_BuiltBuilding(bpy.types.Operator):
    global exportmessage
    bl_idname = "OBJECT_OT_BuiltBuilding"
    bl_label = "Create"
    __doc__ = ""
    
    def invoke(self, context, event):
        scene = context.scene
        buildmeshbuilding(context)
        return {'FINISHED'}
            
class OBJECT_OT_DestoryBuilding(bpy.types.Operator):
    global exportmessage
    bl_idname = "OBJECT_OT_DestoryBuilding"
    bl_label = "Delete"
    __doc__ = ""
    
    def invoke(self, context, event):
        scene = context.scene
        DestoryBuilding(context)
        return {'FINISHED'}

class OBJECT_OT_CreateBuildingFloors(bpy.types.Operator):
    global exportmessage
    bl_idname = "OBJECT_OT_CreateBuildingFloors"
    bl_label = "Create Floor(s)"
    __doc__ = ""
    
    def invoke(self, context, event):
        scene = context.scene
        print("Creating number of " ,scene.buildingfloors ," floor(s)")
        createfloors(context,scene.buildingfloors)
        
        return {'FINISHED'}
        
class OBJECT_OT_CreatePanel(bpy.types.Operator):
    global exportmessage
    bl_idname = "OBJECT_OT_CreatePanel"
    bl_label = "Create Panel"
    __doc__ = ""
    
    def invoke(self, context, event):
        scene = context.scene
        BuildModelMesh()
        return {'FINISHED'}
        
class OBJECT_OT_RemoveFloor(bpy.types.Operator):
    global exportmessage
    bl_idname = "OBJECT_OT_RemoveFloor"
    bl_label = "Remove Floor"
    __doc__ = ""
    
    def invoke(self, context, event):
        scene = context.scene
        buildingstemplates = context.scene.buildingstemplates
        index = buildingstemplates.floors_index
        floors.pop(index)
        updatebuildingfloorlist(context)        
        BuildingConfigs()        
        return {'FINISHED'}
        
class OBJECT_OT_CloneBuildingFloors(bpy.types.Operator):
    global exportmessage
    bl_idname = "OBJECT_OT_CloneBuildingFloors"
    bl_label = "Clone Floor"
    __doc__ = ""
    
    def invoke(self, context, event):
        scene = context.scene
        
        updatebuildingfloorlist(context)
        return {'FINISHED'} 

Part 1


        
def createfloors(context,nofloors):
    if nofloors > 0:
        for i in range(nofloors):
            newfloor = floor()
            floors.append(newfloor)            
    updatebuildingfloorlist(context)
    BuildingConfigs()
def updatebuildingfloorlist(context):
    buildingstemplates = context.scene.buildingstemplates
    count = 0
    if context != None:
        for i in range(len(buildingstemplates.floors)):
            buildingstemplates.floors.remove(0)            
        for floorno in floors:
            list = buildingstemplates.floors.add()
            list.name = "Floor_" + str(count)
            count += 1
def buildmeshbuilding(context):
    meshname = "building"
    objectname = "building"
    bfoundmesh = False
    for obj in bpy.data.objects:
        print("objects",obj.name)
        if obj.type == 'MESH' and obj.name == objectname:
            print("found")
            bfoundmesh = True
    
    if bfoundmesh == False:
        me_ob = bpy.data.meshes.new(meshname)

        faces = []
        edges = []
        verts = []

        verts.extend([(1.000000,1.000000,0.000000)])
        verts.extend([(1.000000,-1.000000,0.000000)]) 
        verts.extend([(-1.000000,-1.000000,0.000000)])
        verts.extend([(-1.000000,1.000000,0.000000)]) 
        faces.extend([(0,2,1)])
        me_ob.from_pydata(verts,edges,faces)
        me_ob.update()
        import add_object_utils
        add_object_utils.add_object_data(context, me_ob)
        print("object created...")
        
    print("finish")

#delete mesh    
def DestoryBuilding(context):
    meshname = "building" 
    objectname = "building"
    for obj in bpy.data.objects:
        obj.select = False;
    for obj in bpy.data.objects:
        if obj.type == 'MESH' and obj.name == objectname:
            obj.select = True            
    bpy.ops.object.delete()

def unpack_list(list_of_tuples):
    l = []
    for t in list_of_tuples:
        l.extend(t)
    return l
def testwalls():
    meshname = "building"
    objectname = "building" 
    faces = []
    verts = []
    edges = []
    
    verts.extend([(1.000000,1.000000 + 1,0.000000)])
    verts.extend([(1.000000,-1.000000 + 1,0.000000)])
    verts.extend([(-1.000000,-1.000000 + 1,0.000000)])
    verts.extend([(-1.000000,1.000000 + 1,0.000000)])
    
    vertount = len(verts)
    faces.extend([(0,2,1)])
    
    return faces, verts

def addtestwalls(_faces,_verts,posz):
    meshname = "building"
    objectname = "building"
    faces = []
    verts = []
    edges = []
    
    vertexcount = len(_verts)
    
    _verts.extend([(1.000000,1.000000,0.000000)]) 
    _verts.extend([(1.000000,-1.000000,0.000000)]) 
    _verts.extend([(-1.000000,-1.000000,0.000000)])
    _verts.extend([(-1.000000,1.000000,0.000000)])
    
    vertount = len(verts)
    _faces.extend([(0+vertexcount,3+vertexcount,2+vertexcount)])
    _faces.extend([(0+vertexcount,2+vertexcount,1+vertexcount)])    
    return _faces, _verts

def BuildingConfigs():
    BuildModelMesh()

def BuildModelMesh():
    meshname = "building" 
    objectname = "building"

    for obj in bpy.data.objects:
        if obj.type == 'MESH' and obj.name == objectname:
            me_ob = bpy.data.meshes.new(meshname) 
            bfoundmesh = True
            faces = []
            edges = []
            verts = []

            faces, verts = testwalls()
            count = 0 
            for floor in floors:            
                vec = mathutils.Vector((0,0,count+0.5))
                faces, verts = addwallpanel(faces,verts,vec,None)
                count += 1                
            me_ob.from_pydata(verts,edges,faces)            
            me_ob.update()
            obj.data = me_ob

def addwallpanel(_faces,_verts,pos,rot):
    meshname = "building" 
    objectname = "building" 
    faces = []
    verts = []
    edges = []
    vertexcount = len(_verts)
    _verts.extend([(1.000000+pos.x,0.000000+pos.y,0.500000+pos.z)])
    _verts.extend([(1.000000+pos.x,0.000000+pos.y,-0.500000+pos.z)]) 
    _verts.extend([(-1.000000+pos.x,0.000000+pos.y,-0.500000+pos.z)])
    _verts.extend([(-1.000000+pos.x,0.000000+pos.y,0.500000+pos.z)]) 
    
    vertount = len(verts)
    _faces.extend([(0+vertexcount,3+vertexcount,2+vertexcount)])
    _faces.extend([(0+vertexcount,2+vertexcount,1+vertexcount)])    
    return _faces, _verts

def register():
    bpy.types.Scene.buildingstemplates = PointerProperty(type=BuildingsSettings, name="Buildings Templates", description="...")

def unregister():
    del bpy.types.Scene.buildingstemplates

if __name__ == "__main__":
    register()    

Part 2

Full script:

cool, this shows lots of potential. :slight_smile: