avd_Logo

avd_Logo
Welcome to the world of mystery.

Building Gen Code


import c4d
import math
from c4d import BaseObject as bo
from c4d import Vector as v
#Welcome to the world of Python

#BUILDING BASE FUNCTION
#----------------------

def BuildingBase(baseBool,baseSplineType,baseHgt,baseWid,baseNumSid,
                        conHgt,conWid,conBevBool,conBevRad,conBevConst,
                        coreBool,coreSize,coreBevBool,coreBevRad,
                 colBool,colType,colNum,colNumDep,colWidth,colDepth,colSides,
                        colSpShp,colOffsetZ,colOffsetX,colRot,colMid,colsubD,colSpc,
                 strBool,numStr,strHgt,strWid,strScale,baseSplineMain,
                        tTagCon,tTagCore,tTagStr):
   
    colSpc/=10

    if (baseSplineType == 0):
        baseSpline = bo(c4d.Osplinerectangle)
        baseSpline[c4d.PRIM_RECTANGLE_WIDTH] = baseWid*2000
        baseSpline[c4d.PRIM_RECTANGLE_HEIGHT] = baseWid*2000
    elif (baseSplineType == 1):
        baseSpline = bo(c4d.Osplinenside)
        baseSpline[c4d.PRIM_NSIDE_SIDES] = baseNumSid
        baseSpline[c4d.PRIM_NSIDE_RADIUS] = baseWid*2000
    elif (baseSplineType == 2):
        baseSpline = bo(c4d.Osplinecircle)
        baseSpline[c4d.PRIM_CIRCLE_RADIUS] = baseWid*2000
    elif (baseSplineType == 3):
        baseSpline = bo(c4d.Osplinecogwheel)
        baseSpline[c4d.PRIM_COGWHEEL_ORAD] = baseWid*2000
        baseSpline[c4d.PRIM_COGWHEEL_IRAD] = baseWid*(1500)
        baseSpline[c4d.PRIM_COGWHEEL_MRAD] = (baseSpline[c4d.PRIM_COGWHEEL_ORAD] + baseSpline[c4d.PRIM_COGWHEEL_IRAD])/2
        baseSpline[c4d.PRIM_COGWHEEL_TEETH] = baseNumSid
    elif (baseSplineType == 4):
        baseSpline = bo(c4d.Osplineflower)
    elif (baseSplineType == 5):
        baseSpline = bo(c4d.Osplinestar)
    elif (baseSplineType == 6):
        baseSpline = baseSplineMain


    baseSpline[c4d.PRIM_PLANE] = 2

    mainNull = bo(c4d.Onull)
    colNull  = bo(c4d.Onull)
    strNull  = bo(c4d.Onull)
    conNull = bo(c4d.Onull)
    coreNull =bo(c4d.Onull)

    colDpthClnrNul = colDCN = bo(c4d.Onull)
    colClnrNul = colCN = bo(c4d.Onull)

    strHgt *= baseHgt/numStr

    sptype = baseSpline.GetType()
    spData = baseSpline.GetData()

    spStr  = bo(sptype)
    spCore = bo(sptype)
    spCon  = bo(sptype)
    spMain = bo(sptype)
    spColShp = bo(440000054)

    spColShp.InsertUnder(colNull)
    spColShp[c4d.MGMOSPLINEOBJECT_STEPS] = int(baseHgt/.5)

    spStr.SetData(spData)
    spCore.SetData(spData)
    spCon.SetData(spData)
    spCore.SetData(spData)
    spMain.SetData(spData)
   

    baseExtObj  = bo(c4d.Oextrude)
    coreExtObj  = bo(c4d.Oextrude)
    conExtObj   = bo(c4d.Oextrude)
    colExtObj   = bo(c4d.Osweep)
    colExtObj[c4d.SWEEPOBJECT_BIRAIL] = False
    colExtObj[c4d.SWEEPOBJECT_RAILDIRECTION] = False
    colExtObj[c4d.SWEEPOBJECT_RAILSCALE]= False
    colExtObj[c4d.CAP_START] = 3
    colExtObj[c4d.CAP_END] = 3
    colExtObj[c4d.SWEEPOBJECT_SPLINESCALE] = colSpShp
#mospline settings
    spColShp[c4d.MGMOSPLINEOBJECT_WIDTH] = 1
    spColShp[c4d.MGMOSPLINEOBJECT_ANGLE_P] = math.radians(-90)
    spColShp[c4d.MGMOSPLINEOBJECT_STEPS] = colsubD
   
   
    baseSpline.SetRelScale(c4d.Vector(baseWid,1,baseWid)) #set the base width of the main spline

    spCon.InsertUnder(conExtObj)
    conExtObj.InsertUnder(conNull)
    conExtObj[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,conHgt+1,0)
    conExtObj[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = baseHgt-conHgt
    conExtObj[c4d.ID_BASEOBJECT_REL_SCALE] = c4d.Vector((1*conWid),1,(1*conWid))
    if(conBevBool == True):
        conExtObj[c4d.CAP_START] = 3
        conExtObj[c4d.CAP_END] = 3
        conExtObj[c4d.CAP_STARTSTEPS] = 1
        conExtObj[c4d.CAP_CONSTRAIN] = conBevConst
        conExtObj[c4d.CAP_ENDSTEPS] = 1
        conExtObj[c4d.CAP_STARTRADIUS] = conBevRad
        conExtObj[c4d.CAP_ENDRADIUS] = conBevRad
       
    conNull.InsertUnder(mainNull)


    colCloner = bo(1018544)
    colCloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 0
    spMain.InsertUnder(mainNull)
    colCloner[c4d.MG_OBJECT_LINK] = spMain
    colCloner[c4d.MG_SPLINE_MODE] = 2
    colCloner[c4d.MG_SPLINE_COUNT] = colNum
    colCloner[c4d.MG_SPLINE_SMOOTH] = True
    colCloner[c4d.ID_MG_TRANSFORM_POSITION,c4d.VECTOR_X] = -colOffsetZ
    colCloner[c4d.MG_SPLINE_OFFSET] = colOffsetX


    strCloner = bo(1018544)
    strCloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 1
    strCloner[c4d.MGCLONER_FIX_CLONES] = False
    strCloner[c4d.MG_LINEAR_COUNT] = numStr
    strCloner[c4d.MG_LINEAR_OBJECT_POSITION,c4d.VECTOR_Y] = strHgt
    strCloner[c4d.MG_LINEAR_OBJECT_SCALE] = c4d.Vector(strWid,1,strWid)

    colClonerDep = bo(1018544)
    colClonerDep[c4d.ID_MG_MOTIONGENERATOR_MODE] = 1
    colClonerDep[c4d.MG_LINEAR_COUNT] = colNumDep
    colClonerDep[c4d.ID_MG_TRANSFORM_ROTATE,c4d.VECTOR_X] = colRot


    if coreBool == True:
        coreExtObj[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,baseHgt-conHgt,0)
        coreExtObj[c4d.ID_BASEOBJECT_REL_SCALE] = c4d.Vector(1*coreSize,1,1*coreSize)
        if(coreBevBool == True):
            coreExtObj[c4d.CAP_START] = 3
            coreExtObj[c4d.CAP_END] = 3
            coreExtObj[c4d.CAP_STARTSTEPS] = 1
            coreExtObj[c4d.CAP_CONSTRAIN] = True
            coreExtObj[c4d.CAP_ENDSTEPS] = 1
            coreExtObj[c4d.CAP_STARTRADIUS] = coreBevRad
            coreExtObj[c4d.CAP_ENDRADIUS] = coreBevRad*coreSize
            if strBool == True:
                coreExtObj[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,(baseHgt-conHgt-coreBevRad*2-numStr*strHgt),0)
                coreExtObj[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = coreBevRad+strHgt*numStr
            else:
                coreExtObj[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,(baseHgt-conHgt-coreBevRad*2)+(coreBevRad/4),0)
                coreExtObj[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = coreBevRad+strHgt

        spCore.InsertUnder(coreExtObj)
        coreExtObj.InsertUnder(coreNull)

        coreNull.InsertUnder(mainNull)
    else:
        spCore.InsertUnder(mainNull)
#define column spline shape
  #--------------------------

    if(colType == 0):
      spCol = bo(c4d.Osplinerectangle)
        spCol[c4d.PRIM_RECTANGLE_WIDTH] = colWidth
        spCol[c4d.PRIM_RECTANGLE_HEIGHT] = colDepth

    elif(colType == 1):
        spCol = bo(c4d.Osplinenside)
        spCol[c4d.PRIM_NSIDE_RADIUS] = colWidth
        spCol[c4d.PRIM_NSIDE_SIDES] = colSides

    elif(colType == 2):
        spCol = bo(c4d.Osplinecircle)
        spCol[c4d.PRIM_CIRCLE_ELLIPSE] = True
        spCol[c4d.PRIM_CIRCLE_RADIUS] = colWidth
        spCol[c4d.PRIM_CIRCLE_RADIUSY] = colDepth

    elif(colType == 3):
        spCol = bo(c4d.Osplinecogwheel)
        spCol[c4d.PRIM_COGWHEEL_TEETH] = colSides
        spCol[c4d.PRIM_COGWHEEL_IRAD] = colWidth
        spCol[c4d.PRIM_COGWHEEL_ORAD] = colDepth
        spCol[c4d.PRIM_COGWHEEL_MRAD] = colMid

    elif(colType == 4):
        spCol = bo(c4d.Osplineflower)
   
    elif(colType == 5):
        spCol = bo(c4d.Osplinestar)

    spCol[c4d.PRIM_PLANE] = 0

#GET THE RADIUS FOR COLUMNS AND SET THEIR DISTANCE
    colRad = spCol.GetRad()
    colClonerDep[c4d.MG_LINEAR_OBJECT_POSITION] = c4d.Vector((colRad.x*(colSpc/2)*100)*4,0,0)
    c4d.EventAdd()
 #stairs
    strExtObj    = bo(c4d.Oextrude)
    strExtObj[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,strHgt,0)
    strExtObj[c4d.CAP_START] = 0


    if (strHgt>.5):
        strExtObj[c4d.CAP_END] = 3
        strExtObj[c4d.CAP_ENDRADIUS] = strHgt/numStr
    else:
        strExtObj[c4d.CAP_END] = 1

#column extrusion settings


    spColShp[c4d.MGMOSPLINEOBJECT_LENGTH] = baseHgt-conHgt



    spStr.InsertUnder(strExtObj)

    spColShp.InsertUnder(colExtObj)
    spCol.InsertUnder(colExtObj)

    colExtObj.InsertUnder(colNull)
    if colBool == True:
        if (colNumDep>1)&(colSpc>0):

            colNull.InsertUnder(colClonerDep)
            colDCN.InsertUnder(colCloner)
            colClonerDep.InsertUnder(colDCN)
            colCloner.InsertUnder(colCN)
            c4d.EventAdd()
        else:
            colNull.InsertUnder(colCloner)
            colCloner.InsertUnder(mainNull)
            c4d.EventAdd()

    strExtObj.InsertUnder(strNull)
    strNull.InsertUnder(strCloner)
   
    if strBool == True:
        strCloner.InsertUnder(mainNull)
    mainNull.SetRelScale(c4d.Vector(baseWid,1,baseWid))
    colPosY = strHgt*numStr
    colPos = c4d.Vector(0,colPosY,0)
    colCN.InsertUnder(mainNull)
    colCN.SetRelPos(colPos)
    strNull.SetRelScale(strScale)
    strNull.SetRelPos(c4d.Vector(0,(numStr/(strHgt*100))/2,0))
    if (baseSplineType == 4):
        spColShp[c4d.MGMOSPLINEOBJECT_ANGLE_P] = math.radians(90)
    elif(baseSplineType == 5):
        spColShp[c4d.MGMOSPLINEOBJECT_ANGLE_P] = math.radians(90)
    else:
        spColShp[c4d.MGMOSPLINEOBJECT_ANGLE_P] = math.radians(-90)
#___________________________

#final mateiral assignment

#___________________________

    if(tTagCon!=None):
        if(tTagCon.CheckType(c4d.Mmaterial)):
            blanktagCon = c4d.BaseTag(c4d.Ttexture)
            blanktagCon.SetMaterial(tTagCon)
            blanktagCon[c4d.TEXTURETAG_PROJECTION] = 3
            tTagCon = blanktagCon.GetClone()
            colCloner.InsertTag(tTagCon)
            conNull.InsertTag(tTagCon)
        elif(tTagCon.CheckType(c4d.Ttexture)):
            tTagCon = tTagCon
            colCloner.InsertTag(tTagCon.GetClone())
            conNull.InsertTag(tTagCon.GetClone())
    else:
        blanktagCon = c4d.BaseTag(c4d.Ttexture)
        colCloner.InsertTag(blanktagCon)
        conNull.InsertTag(blanktagCon)

    if(tTagStr!=None):
        if(tTagStr.CheckType(c4d.Mmaterial)):
            blanktagStr = c4d.BaseTag(c4d.Ttexture)
            blanktagStr.SetMaterial(tTagCon)
            blanktagStr[c4d.TEXTURETAG_PROJECTION] = 3
            tTagStr = blanktagCon.GetClone()
            strNull.InsertTag(tTagStr)
        else:
            tTagStr = tTagStr
            strNull.InsertTag(tTagStr.GetClone())
    else:
        blanktagStr = c4d.BaseTag(c4d.Ttexture)
        strNull.InsertTag(blanktagStr)

    if(tTagCore!=None):
        if(tTagCore.CheckType(c4d.Mmaterial)):
            blanktagCore = c4d.BaseTag(c4d.Ttexture)
            blanktagCore.SetMaterial(tTagCore)
            blanktagCore[c4d.TEXTURETAG_PROJECTION] = 3
            tTagCore = blanktagCore.GetClone()
            coreNull.InsertTag(tTagCore)
        else:
            tTagCore = tTagCore
            coreNull.InsertTag(tTagCore.GetClone())
    else:
        blanktagCore = c4d.BaseTag(c4d.Ttexture)
        coreNull.InsertTag(blanktagCore)
    return mainNull





#-----------------------------------------------------------
#****************BASIC MODELING FUNCTIONS*******************
#-----------------------------------------------------------




#---------make object editable----------#

def MakeEditable(op):
    if (not op) | op.CheckType(c4d.Opolygon) | op.CheckType(c4d.Ospline): return op

    op = [op.GetClone()]
    doc = c4d.documents.BaseDocument()
    doc.InsertObject(op[0],None,None)
    op = c4d.utils.SendModelingCommand(
                              command = c4d.MCOMMAND_MAKEEDITABLE,
                              list = op,
                              mode = c4d.MODELINGCOMMANDMODE_EDGESELECTION,
                              doc = doc )
    return op[0]
#---------Connect and Delete Splines----------#


#-WorkInProgress!!!--------Optimize----------#

def Optimize(op):
    if (not op) | op.CheckType(c4d.Opolygon) | op.CheckType(c4d.Ospline): return op

    op = [op.GetClone()]
    doc = c4d.documents.BaseDocument()
    doc.InsertObject(op[0],None,None)
    op = c4d.utils.SendModelingCommand(
                              command = c4d.MCOMMAND_MAKEEDITABLE,
                              list = op,
                              mode = c4d.MODELINGCOMMANDMODE_EDGESELECTION,
                              doc = doc )
    return op[0]

#END BASIC MODELING FUNCTIONS
#-----------------------------------------------------------------


#----!!!!WIP!!!--------------BASE BUILDING SPLINE GENERATOR--------------------------
def BaseSpline(btype, width, depth, bevBool, bevRadius,sSubD,sSubDType,
                sSubDAngle, numSides, sSubDLen, sliceMax, sliceMin, sliceBool,
                innerBoolsqr,innerOffsetSqr, #square hollow settings
                innerBoolNside,innerOffsetNside, #n sided hollow settings
                ProfShpTyp,profS,profT):


#   Bldg Type 1 = Rectangle
    if btype == 0:

        bSpline = c4d.BaseObject(c4d.Osplinerectangle)

        bSpline[c4d.PRIM_RECTANGLE_WIDTH] = width
        bSpline[c4d.PRIM_RECTANGLE_HEIGHT] = depth
        bSpline[c4d.PRIM_RECTANGLE_ROUNDING] = bevBool

        if(bevRadius>=width/2) or (bevRadius>=depth/2):
            if(width>=depth):
                bevRadius = depth/2
            elif(depth>=width):
                bevRadius = width/2
        bSpline[c4d.PRIM_RECTANGLE_RADIUS] = bevRadius
        bSpline[c4d.PRIM_PLANE] = 2
        bSpline[c4d.SPLINEOBJECT_INTERPOLATION] = sSubDType
        bSpline[c4d.SPLINEOBJECT_ANGLE] = sSubDAngle
        bSpline[c4d.SPLINEOBJECT_SUB] = sSubD
        bSpline[c4d.SPLINEOBJECT_MAXIMUMLENGTH] = sSubDLen

        if innerBoolsqr == True:
            bSplineInner = c4d.BaseObject(c4d.Osplinerectangle)
            connectObj = c4d.BaseObject(1011010)
            bSplineInner[c4d.PRIM_RECTANGLE_WIDTH] = width-innerOffsetSqr
            bSplineInner[c4d.PRIM_RECTANGLE_HEIGHT] = depth-innerOffsetSqr
            bSplineInner[c4d.PRIM_PLANE] = 2
            bSplineInner.InsertUnder(connectObj)
            bSpline.InsertUnder(connectObj)
            return connectObj
        return bSpline.GetClone()

#   Bldg Type 2 = N-Sided
    if btype == 1:

        bSpline = c4d.BaseObject(c4d.Osplinenside)

        bSpline[c4d.PRIM_NSIDE_SIDES] = numSides
        bSpline[c4d.PRIM_NSIDE_RADIUS] = width/2
        bSpline[c4d.PRIM_NSIDE_ROUNDING] = bevBool
        bSpline[c4d.PRIM_NSIDE_RRADIUS] = bevRadius
        bSpline[c4d.PRIM_PLANE] = 2
        bSpline[c4d.SPLINEOBJECT_INTERPOLATION] = sSubDType
        bSpline[c4d.SPLINEOBJECT_ANGLE] = sSubDAngle
        bSpline[c4d.SPLINEOBJECT_SUB] = sSubD
        bSpline[c4d.SPLINEOBJECT_MAXIMUMLENGTH] = sSubDLen

        if innerBoolNside == True:
            bSplineInner = c4d.BaseObject(c4d.Osplinenside)
            connectObj = c4d.BaseObject(1011010)
            bSplineInner[c4d.PRIM_NSIDE_SIDES] = numSides
            bSplineInner[c4d.PRIM_NSIDE_RADIUS] = (width/2)-innerOffsetNside
            bSplineInner[c4d.PRIM_NSIDE_ROUNDING] = bevBool
            bSplineInner[c4d.PRIM_NSIDE_RRADIUS] = bevRadius
            bSplineInner[c4d.PRIM_PLANE] = 2
            bSplineInner[c4d.SPLINEOBJECT_INTERPOLATION] = sSubDType
            bSplineInner[c4d.SPLINEOBJECT_ANGLE] = sSubDAngle
            bSplineInner[c4d.SPLINEOBJECT_SUB] = sSubD
            bSplineInner[c4d.SPLINEOBJECT_MAXIMUMLENGTH] = sSubDLen
            bSplineInner.InsertUnder(connectObj)
            bSpline.InsertUnder(connectObj)
            return connectObj
        return bSpline.GetClone()

#   Bldg Type 3 = Circle
    if btype == 2:
        if (sliceBool == 0) :
            bSpline = c4d.BaseObject(c4d.Osplinecircle)
            bSpline[c4d.PRIM_CIRCLE_ELLIPSE] = True
            bSpline[c4d.PRIM_CIRCLE_RADIUS] = width/2
            bSpline[c4d.PRIM_CIRCLE_RADIUSY] = depth/2
        if (sliceBool != 0) :
            bSpline = c4d.BaseObject(c4d.Osplinearc)
            bSpline[c4d.PRIM_ARC_TYPE] = 3
            bSpline[c4d.PRIM_ARC_RADIUS] = width/2
            bSpline[c4d.PRIM_ARC_INNER] = depth/2
            bSpline[c4d.PRIM_ARC_START] = sliceMin
            bSpline[c4d.PRIM_ARC_END] = sliceMax

        bSpline[c4d.PRIM_PLANE] = 2
        bSpline[c4d.SPLINEOBJECT_INTERPOLATION] = sSubDType
        bSpline[c4d.SPLINEOBJECT_ANGLE] = sSubDAngle
        bSpline[c4d.SPLINEOBJECT_SUB] = sSubD
        bSpline[c4d.SPLINEOBJECT_MAXIMUMLENGTH] = sSubDLen
        return bSpline.GetClone()

#   Bldg Type 4 = Profile Curve
    if btype == 3:
        bSpline = c4d.BaseObject(c4d.Osplineprofile)
        bSpline[c4d.PRIM_PROFILE_B] = width/2
        bSpline[c4d.PRIM_PROFILE_A] = depth/2
        bSpline[c4d.PRIM_PROFILE_S] = profS
        bSpline[c4d.PRIM_PROFILE_T] = profT
        bSpline[c4d.PRIM_PROFILE_TYPE] = ProfShpTyp
        bSpline[c4d.PRIM_PLANE] = 2
        bSpline[c4d.SPLINEOBJECT_INTERPOLATION] = sSubDType
        bSpline[c4d.SPLINEOBJECT_ANGLE] = sSubDAngle
        bSpline[c4d.SPLINEOBJECT_SUB] = sSubD
        bSpline[c4d.SPLINEOBJECT_MAXIMUMLENGTH] = sSubDLen

        return bSpline.GetClone()

#END BASE BUILDING SPLINE GENERATION
#---------------------------------------------------------------


#   MUTLI BLOCK GENERATOR
def MultiBlock(numBlocks,numFlrs,width,depth,hgt,rOff,eList,
                tex1,tex2,tex3,rtex,seed,bDist,
                bevBool, bevRadius,
                sSubD, sSubDType, sSubDAngle, sSubDLen):
    blankTex1Tag = c4d.BaseTag(c4d.Ttexture)
    blankTex2Tag = c4d.BaseTag(c4d.Ttexture)
    blankTex3Tag = c4d.BaseTag(c4d.Ttexture)
    blankRTexTagR2 = c4d.BaseTag(c4d.Ttexture)
    blankRTexTagC2 = c4d.BaseTag(c4d.Ttexture)
    blankRTexTagR2[c4d.TEXTURETAG_RESTRICTION] = "R2"
    blankRTexTagC2[c4d.TEXTURETAG_RESTRICTION] = "C2"
    blankMat = c4d.BaseMaterial(c4d.Mmaterial)
    blankTex1Tag.SetMaterial(blankMat)

    rOff *= numBlocks

    BaseSpline = c4d.BaseObject(c4d.Osplinerectangle)#Call Basic rectangular spline

    BodyExtrude1 = c4d.BaseObject(c4d.Oextrude)#call extrude1
    BodyExtrude2 = c4d.BaseObject(c4d.Oextrude)#extrude2
    BodyExtrude3 = c4d.BaseObject(c4d.Oextrude)#extrude3
    BodyExtrude4 = c4d.BaseObject(c4d.Oextrude)#extrude3
    BodyExtrude5 = c4d.BaseObject(c4d.Oextrude)#extrude3

    cloner = c4d.BaseObject(1018544)#call cloner object

    if(bDist == 0):
        cloner[c4d.MGCLONER_MODE] = 2
    elif(bDist == 1):
        cloner[c4d.MGCLONER_MODE] = 1
    cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 3#set to grid cloner
    cloner[c4d.MG_GRID_RESOLUTION] = c4d.Vector(numBlocks,1,numBlocks)
    cloner[c4d.MG_GRID_SIZE] = c4d.Vector(width,0,depth)
    cloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] = eList
    cloner[c4d.MGCLONER_SEED] = seed

    BaseSpline[c4d.PRIM_RECTANGLE_WIDTH] = ((width/numBlocks))
    BaseSpline[c4d.PRIM_RECTANGLE_HEIGHT] = ((depth/numBlocks))
    BaseSpline[c4d.PRIM_PLANE] = 2
    BaseSpline[c4d.PRIM_RECTANGLE_ROUNDING] = bevBool
    if (bevRadius > ((width/2)-1))or(bevRadius > ((depth/2)-1)):
        if width>depth: BaseSpline[c4d.PRIM_RECTANGLE_RADIUS] = depth/2
        else:BaseSpline[c4d.PRIM_RECTANGLE_RADIUS] = width/2
    else : BaseSpline[c4d.PRIM_RECTANGLE_RADIUS] = (bevRadius/numBlocks)


    BaseSpline[c4d.SPLINEOBJECT_SUB] = sSubD
    BaseSpline[c4d.SPLINEOBJECT_INTERPOLATION] = sSubDType
    BaseSpline[c4d.SPLINEOBJECT_ANGLE] = sSubDAngle
    BaseSpline[c4d.SPLINEOBJECT_MAXIMUMLENGTH] = sSubDLen

    #are the materials empty?
    if tex1 == None:
            BodyExtrude1.InsertTag(blankTex1Tag)
            BodyExtrude4.InsertTag(blankTex1Tag)
    if tex2 == None:
            BodyExtrude2.InsertTag(blankTex2Tag)
            BodyExtrude5.InsertTag(blankTex2Tag)
    if tex3 == None:
            BodyExtrude3.InsertTag(blankTex3Tag)
    if rtex == None:
            BodyExtrude1.InsertTag(blankRTexTagR2.GetClone())
            BodyExtrude1.InsertTag(blankRTexTagC2.GetClone())
            BodyExtrude2.InsertTag(blankRTexTagR2.GetClone())
            BodyExtrude2.InsertTag(blankRTexTagC2.GetClone())
            BodyExtrude3.InsertTag(blankRTexTagR2.GetClone())
            BodyExtrude3.InsertTag(blankRTexTagC2.GetClone())
            BodyExtrude4.InsertTag(blankRTexTagR2.GetClone())
            BodyExtrude4.InsertTag(blankRTexTagC2.GetClone())
            BodyExtrude5.InsertTag(blankRTexTagR2.GetClone())
            BodyExtrude5.InsertTag(blankRTexTagC2.GetClone())            


    #What type of fucking texture obj user has pulled in?
    if tex1 != None: t1TRUE = tex1.CheckType(c4d.Ttexture)
    if tex2 != None: t2TRUE = tex2.CheckType(c4d.Ttexture)
    if tex3 != None: t3TRUE = tex3.CheckType(c4d.Ttexture)
    if rtex != None: rtTRUE = rtex.CheckType(c4d.Ttexture)

    if rtex != None:
        if(rtex.CheckType(c4d.Mmaterial)):
            blanktagRoofR2 = c4d.BaseTag(c4d.Ttexture)
            blanktagRoofR2.SetMaterial(rtex)
            blanktagRoofR2[c4d.TEXTURETAG_PROJECTION] = 3
            blanktagRoofR2[c4d.TEXTURETAG_RESTRICTION] = "R2"

            blanktagRoofC2 = c4d.BaseTag(c4d.Ttexture)
            blanktagRoofC2.SetMaterial(rtex)
            blanktagRoofC2[c4d.TEXTURETAG_PROJECTION] = 3
            blanktagRoofC2[c4d.TEXTURETAG_RESTRICTION] = "C2"
           
            BodyExtrude1.InsertTag(blanktagRoofR2.GetClone())
            BodyExtrude1.InsertTag(blanktagRoofC2.GetClone())
            BodyExtrude2.InsertTag(blanktagRoofR2.GetClone())
            BodyExtrude2.InsertTag(blanktagRoofC2.GetClone())
            BodyExtrude3.InsertTag(blanktagRoofR2.GetClone())
            BodyExtrude3.InsertTag(blanktagRoofC2.GetClone())
            BodyExtrude4.InsertTag(blanktagRoofR2.GetClone())
            BodyExtrude4.InsertTag(blanktagRoofC2.GetClone())
            BodyExtrude5.InsertTag(blanktagRoofR2.GetClone())
            BodyExtrude5.InsertTag(blanktagRoofC2.GetClone())
           
        elif(rtex.CheckType(c4d.Ttexture)):
            roofTagR2 = rtex.GetClone()
            roofTagR2[c4d.TEXTURETAG_RESTRICTION] = "R2"
            roofTagC2 = rtex.GetClone()
            roofTagC2[c4d.TEXTURETAG_RESTRICTION] = "C2"
            BodyExtrude1.InsertTag(roofTagR2.GetClone())
            BodyExtrude1.InsertTag(roofTagC2.GetClone())
            BodyExtrude2.InsertTag(roofTagR2.GetClone())
            BodyExtrude2.InsertTag(roofTagC2.GetClone())
            BodyExtrude3.InsertTag(roofTagR2.GetClone())
            BodyExtrude3.InsertTag(roofTagC2.GetClone())
            BodyExtrude4.InsertTag(roofTagR2.GetClone())
            BodyExtrude4.InsertTag(roofTagC2.GetClone())
            BodyExtrude5.InsertTag(roofTagR2.GetClone())
            BodyExtrude5.InsertTag(roofTagC2.GetClone())

        if (not rtTRUE):
                print "!!ERROR!! DANGER WILL ROBINSON !!ERROR!!"
                print "You fucked up."
                print "Please place a <TextureTag> instead of:"
                print rtex.GetName()

    if tex3 != None:
        if(tex3.CheckType(c4d.Mmaterial)):
            blanktagT1 = c4d.BaseTag(c4d.Ttexture)
            blanktagT1.SetMaterial(tex3)
            blanktagT1[c4d.TEXTURETAG_PROJECTION] = 3
            BodyExtrude3.InsertTag(blanktagT1.GetClone())

        elif(tex3.CheckType(c4d.Ttexture)):
            BodyExtrude3.InsertTag(tex3.GetClone())

        if (not t3TRUE):
                print "!!ERROR!! DANGER WILL ROBINSON !!ERROR!!"
                print "You fucked up."
                print "Please place a <TextureTag> instead of:"
                print tex3.GetName()

    if tex2 != None:
        if(tex2.CheckType(c4d.Mmaterial)):
            blanktagT2 = c4d.BaseTag(c4d.Ttexture)
            blanktagT2.SetMaterial(tex2)
            blanktagT2[c4d.TEXTURETAG_PROJECTION] = 3
            BodyExtrude2.InsertTag(blanktagT2.GetClone())
            BodyExtrude5.InsertTag(blanktagT2.GetClone())

        elif(tex2.CheckType(c4d.Ttexture)):
            BodyExtrude2.InsertTag(tex2.GetClone())
            BodyExtrude5.InsertTag(tex2.GetClone())
        if (not t2TRUE):
                print "!!ERROR!! DANGER WILL ROBINSON !!ERROR!!"
                print "You fucked up."
                print "Please place a <TextureTag> instead of:"
                print tex2.GetName()

    if tex1 != None:
        if(tex1.CheckType(c4d.Mmaterial)):
            blanktagT2 = c4d.BaseTag(c4d.Ttexture)
            blanktagT2.SetMaterial(tex1)
            blanktagT2[c4d.TEXTURETAG_PROJECTION] = 3
            BodyExtrude2.InsertTag(blanktagT2.GetClone())
            BodyExtrude5.InsertTag(blanktagT2.GetClone())

        elif(tex1.CheckType(c4d.Ttexture)):
            BodyExtrude1.InsertTag(tex1.GetClone())
            BodyExtrude4.InsertTag(tex1.GetClone())
        if (not t1TRUE):
                print "!!ERROR!! DANGER WILL ROBINSON !!ERROR!!"
                print "You fucked up."
                print "Please place a <TextureTag> instead of:"
                print tex1.GetName()



    #extrude 1
    BodyExtrude1[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,hgt,0)
    BodyExtrude1[c4d.CAP_END] = 3
    BodyExtrude1[c4d.CAP_ROUNDING] = 6
    BodyExtrude1[c4d.CAP_ENDRADIUS] = rOff/10
    BodyExtrude1[c4d.CAP_CONSTRAIN] = False
    BodyExtrude1[c4d.EXTRUDEOBJECT_SUB] = numFlrs

    BSCopy1 = BaseSpline.GetClone()
    BSCopy1.InsertUnder(BodyExtrude1)
    BodyExtrude1.InsertUnder(cloner)

    #extrude 2
    BodyExtrude2[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,hgt/1.4,0)
    BodyExtrude2[c4d.CAP_END] = 3
    BodyExtrude2[c4d.CAP_ROUNDING] = 6
    BodyExtrude2[c4d.CAP_ENDRADIUS] = rOff/10
    BodyExtrude2[c4d.CAP_CONSTRAIN] = True
    BodyExtrude2[c4d.EXTRUDEOBJECT_SUB] = numFlrs

    BSCopy2 = BaseSpline.GetClone()
    BSCopy2.InsertUnder(BodyExtrude2)
    BodyExtrude2.InsertUnder(cloner)

    #extrude 3
    BodyExtrude3[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,hgt/1.8,0)
    BodyExtrude3[c4d.CAP_END] = 3
    BodyExtrude3[c4d.CAP_ROUNDING] = 6
    BodyExtrude3[c4d.CAP_ENDRADIUS] = rOff/10
    BodyExtrude3[c4d.CAP_CONSTRAIN] = True
    BodyExtrude3[c4d.EXTRUDEOBJECT_SUB] = numFlrs


    BSCopy3 = BaseSpline.GetClone()
    BSCopy3.InsertUnder(BodyExtrude3)
    BodyExtrude3.InsertUnder(cloner)

    #extrude 4
    BodyExtrude4[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,hgt/2.2,0)
    BodyExtrude4[c4d.CAP_END] = 3
    BodyExtrude4[c4d.CAP_ROUNDING] = 6
    BodyExtrude4[c4d.CAP_ENDRADIUS] = rOff/10
    BodyExtrude4[c4d.CAP_CONSTRAIN] = True
    BodyExtrude4[c4d.EXTRUDEOBJECT_SUB] = numFlrs


    BSCopy4 = BaseSpline.GetClone()
    BSCopy4.InsertUnder(BodyExtrude4)
    BodyExtrude4.InsertUnder(cloner)

    #extrude 5
    BodyExtrude5[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,hgt/2.5,0)
    BodyExtrude5[c4d.CAP_END] = 3
    BodyExtrude5[c4d.CAP_ROUNDING] = 6
    BodyExtrude5[c4d.CAP_ENDRADIUS] = rOff/10
    BodyExtrude5[c4d.CAP_CONSTRAIN] = True
    BodyExtrude5[c4d.EXTRUDEOBJECT_SUB] = numFlrs

    BSCopy5 = BaseSpline.GetClone()
    BSCopy5.InsertUnder(BodyExtrude5)
    BodyExtrude5.InsertUnder(cloner)

    #base settings/return func
    cloner[c4d.MGCLONER_VOLUMEINSTANCES] = False
    return cloner.GetClone()






#    MAIN FLOOR GENERATOR(Extrude->cloner)
def FloorExtrudeObj(spline, flrHgt, numFlrs, bevTop, bevBot,mainfx,noCaps):

    flrObj = c4d.BaseObject(c4d.Oextrude)
    conSpline = spline.GetClone()
    conSpline.SetRelScale(v(1,1,1))
    flrNull = bo(c4d.Onull)
    flrHgt -= bevTop+bevBot
    flrObj[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,flrHgt,0)
    flrObj.SetRelPos(c4d.Vector(0,flrHgt/2,0))
    flrObj[c4d.CAP_CONSTRAIN] = False
    flrObj[c4d.CAP_START] = 3
    flrObj[c4d.CAP_END] = 3
    flrObj[c4d.CAP_STARTRADIUS] = bevBot
    flrObj[c4d.CAP_ENDRADIUS]= bevTop
    if noCaps == True:
        flrObj[c4d.CAP_START] = 0
        flrObj[c4d.CAP_END] = 0
    spline.InsertUnder(flrObj)
    flrObj.InsertUnder(flrNull)
    return flrNull
#END MAIN FLOOR GENERATOR
#--------------------------------------------------------







#    MULLION GENERATOR

def Mullion(obj,mulWidth, pBool, sSubD):
    if (mulWidth==0):
        return
    mul = c4d.BaseObject(c4d.Oatomarray)
    mul[c4d.ATOMARRAYOBJECT_SRAD] = mulWidth
    mul[c4d.ATOMARRAYOBJECT_CRAD] = mulWidth
    mul[c4d.ATOMARRAYOBJECT_SUB]  = sSubD
    if pBool == False:
        MakeEditable(mul)
        pTag = c4d.BaseTag(c4d.Tphong)
        pTag[c4d.PHONGTAG_PHONG_ANGLELIMIT] = True
        pTag[c4d.PHONGTAG_PHONG_ANGLE] = 0
        mul.InsertTag(pTag)

    obj.InsertUnder(mul)
    mulEd = MakeEditable(mul)

    return mulEd.GetClone()
#END MULLION GENERATOR
#---------------------------------------------------------









#    ROOF GENERATOR

def Roof(rtype, flrHgt, numFlrs, roofSize,rcBool):
    roof = c4d.BaseObject(c4d.Oextrude)
    if rtype == 0:
        roof = c4d.BaseObject(c4d.Oextrude)
        roof[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,roofSize/2,0)
        roof[c4d.CAP_START] = 1
        roof[c4d.CAP_END] = 3
        roof[c4d.CAP_ROUNDING] = 6
        roof[c4d.CAP_ENDRADIUS] = roofSize/2.1
        roof[c4d.CAP_CONSTRAIN] = rcBool
        if rcBool == False: roof[c4d.CAP_START] = 1

    elif rtype == 1:
        roof = c4d.BaseObject(c4d.Oextrude)
        roof[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,roofSize/2,0)
        roof[c4d.CAP_START] = 1
        roof[c4d.CAP_END] = 3
        roof[c4d.CAP_ROUNDING] = 5
        roof[c4d.CAP_ENDRADIUS] = roofSize
        roof[c4d.CAP_CONSTRAIN] = rcBool
        if rcBool == False: roof[c4d.CAP_START] = 1

    elif rtype == 2:
        roof = c4d.BaseObject(c4d.Oextrude)
        roof[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,roofSize/2,0)
        roof[c4d.CAP_START] = 1
        roof[c4d.CAP_END] = 3
        roof[c4d.CAP_ENDSTEPS] = (2*int(roofSize/100))+4
        roof[c4d.CAP_ROUNDING] = 2
        roof[c4d.CAP_ENDRADIUS] = roofSize
        roof[c4d.CAP_CONSTRAIN] = rcBool
        if rcBool == False: roof[c4d.CAP_START] = 1

    elif rtype == 3:
        roof = c4d.BaseObject(c4d.Oextrude)
        roof[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,roofSize/2,0)
        roof[c4d.CAP_START] = 1
        roof[c4d.CAP_END] = 3
        roof[c4d.CAP_ENDSTEPS] = 4*int(roofSize*2)
        roof[c4d.CAP_ROUNDING] = 3
        roof[c4d.CAP_ENDRADIUS] = roofSize/2
        roof[c4d.CAP_CONSTRAIN] = rcBool
        if rcBool == False: roof[c4d.CAP_START] = 1


    elif rtype == 4:
        roof = c4d.BaseObject(c4d.Oextrude)
        roof[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,roofSize/6,0)
        roof[c4d.CAP_START] = 1
        roof[c4d.CAP_END] = 3
        roof[c4d.CAP_ROUNDING] = 1
        roof[c4d.CAP_ENDSTEPS] = 4
        roof[c4d.CAP_ENDRADIUS] = roofSize/4
        roof[c4d.CAP_CONSTRAIN] = rcBool
        if rcBool == False: roof[c4d.CAP_START] = 1
       
    return roof
#END ROOF GENERATOR
#-------------------------------------------------------------










#-------------------------------------------------------------
#****************MAIN FUNCTION********************************
#-------------------------------------------------------------

def main():

    doc = c4d.documents.BaseDocument()
    Adoc = c4d.documents.GetActiveDocument()

#---------Get User Data From Python Object---------#

    instBool = op[c4d.ID_USERDATA,78]#instancing on/off

    coltype = op[c4d.ID_USERDATA,135]#
    baseSplineType = op[c4d.ID_USERDATA,121]#

    baseBool = op[c4d.ID_USERDATA,123]#
    baseHgt = op[c4d.ID_USERDATA,124]#
    baseWid = op[c4d.ID_USERDATA,125]#

    coreBool = op[c4d.ID_USERDATA,129]#
    coreSize = op[c4d.ID_USERDATA,130]#percentage
    coreBevBool = op[c4d.ID_USERDATA,131]#
    coreBevRad = op[c4d.ID_USERDATA,119]

    conHgt = op[c4d.ID_USERDATA,114]#
    conWid = op[c4d.ID_USERDATA,115]#
    conBevBool = op[c4d.ID_USERDATA,116]#
    conBevRad = op[c4d.ID_USERDATA,119]#
    conBevConst = op[c4d.ID_USERDATA,117]#
    colNum = op[c4d.ID_USERDATA,136]#
    colBool = op[c4d.ID_USERDATA,134]#
    colType = op[c4d.ID_USERDATA,135]#
    colWid = op[c4d.ID_USERDATA,142]#
    colDep = op[c4d.ID_USERDATA,143]#
    colSides = op[c4d.ID_USERDATA,73]#
    colSpShp = op[c4d.ID_USERDATA,145]#
    colOffsetZ = op[c4d.ID_USERDATA,138]#
    colOffsetX = op[c4d.ID_USERDATA,139]#
    colMid = op[c4d.ID_USERDATA,85]#
    colNumDep = op[c4d.ID_USERDATA,137]#
    colRot = op[c4d.ID_USERDATA,141]#
    colBev = op[c4d.ID_USERDATA,153]#
    colsubD = op[c4d.ID_USERDATA,144]#
    colSpc  = op[c4d.ID_USERDATA,140]#

    strBool = op[c4d.ID_USERDATA,148]
    numStr = op[c4d.ID_USERDATA,149]
    strHgt = op[c4d.ID_USERDATA,151] #percentage
    strWid = op[c4d.ID_USERDATA,150]
    strScale = op[c4d.ID_USERDATA,89]
    baseNumSid = op[c4d.ID_USERDATA,154]
#baseBool,baseSpline,baseHgt,baseWid,
#coreBool,coreSize,
#colBool,colType,colNum,colWidth,colDepth,colSides,
#strBool,strNum,strWidth




#   BUILDING TYPE

    btype = bldgType = op[c4d.ID_USERDATA,11]

#   BUILDING SETTINGS
    mainScale          = op[c4d.ID_USERDATA,69]
    width              = op[c4d.ID_USERDATA,2]
    depth              = op[c4d.ID_USERDATA,3]
    bevBool            = op[c4d.ID_USERDATA,4]
    bevRadius          = op[c4d.ID_USERDATA,5]
    bevRadID           = 5
    if width>=depth: bevRadLim  = depth/2
    if depth>=width: bevRadLim  = width/2

#   FLOOR GENERATOR SETTINGS
    mainfx             = op[c4d.ID_USERDATA,41]
    flrHgt             = op[c4d.ID_USERDATA,6]
    numFlrs            = op[c4d.ID_USERDATA,15]
    flrBase            = op[c4d.ID_USERDATA,57]

#   BaseSpline Settings
    sSubD              = op[c4d.ID_USERDATA,8]
    sSubDType          = op[c4d.ID_USERDATA,7]
    sSubDAngle         = op[c4d.ID_USERDATA,9]
    sSubDLen           = op[c4d.ID_USERDATA,10]
    numSides           = op[c4d.ID_USERDATA,27]

    bevTop             = op[c4d.ID_USERDATA,16]
    bevTopID           = 16

    bevBot             = op[c4d.ID_USERDATA,17]
    bevBotID           = 17

    bevBotLim          = (flrHgt-bevTop)-5
    bevTopLim          = (flrHgt-bevBot)-5

    sliceMin           = op[c4d.ID_USERDATA,31]
    sliceMax           = op[c4d.ID_USERDATA,25]
    sliceBool          = op[c4d.ID_USERDATA,26]

    innerBool          = op[c4d.ID_USERDATA,28]
    inOffsetSqr        = op[c4d.ID_USERDATA,29]

    innerBoolNside     = op[c4d.ID_USERDATA,55]
    iBNs = innerBoolNside#shortcut

    innerOffsetNside   = op[c4d.ID_USERDATA,56]
    iONs = innerOffsetNside#shortcut

    mulWidth   =  mW   = op[c4d.ID_USERDATA,33]
    mulBool    =  mB   = op[c4d.ID_USERDATA,32]
    mulPBool   =  mPB  = op[c4d.ID_USERDATA,34]
    mulSubD    =  mSD  = int(op[c4d.ID_USERDATA,54])

    profShpTyp =  pST  = op[c4d.ID_USERDATA,23]
    profS      =  pS   = op[c4d.ID_USERDATA,59]
    profT      =  pT   = op[c4d.ID_USERDATA,60]

    conSepBool = op[c4d.ID_USERDATA,18]
    conSepHgt = op[c4d.ID_USERDATA,14]
   
   
    #ROOF SETTINGS
    rtype      = op[c4d.ID_USERDATA,42]
    roofSize   = op[c4d.ID_USERDATA,44]
    roofBool   = op[c4d.ID_USERDATA,53]
    rObjBool   = op[c4d.ID_USERDATA,45]
    rNumObj    = op[c4d.ID_USERDATA,51]
    ventsBool  = op[c4d.ID_USERDATA,48]
    antenBool  = op[c4d.ID_USERDATA,49]
    pipes      = op[c4d.ID_USERDATA,50]

    rcBool     = op[c4d.ID_USERDATA,70]
    roofScale  = op[c4d.ID_USERDATA,71]

    roofObjList = rol = op[c4d.ID_USERDATA,87]
    rolCnt = rol.GetObjectCount()

    #MULTI BLOCK SETTINGS
    numBlocks  =  nB   = op[c4d.ID_USERDATA,58]
    height     =  flrHgt*numFlrs
    rOff       =  roofSize
    rOffId     =  8
    eList      =  op[c4d.ID_USERDATA,62]
    seed       =  op[c4d.ID_USERDATA,61]
    bDist      =  op[c4d.ID_USERDATA,63]

#INTERIOR SETTINGS



    intBaseBool = op[c4d.ID_USERDATA,88]
    intbaseHgt = flrHgt
    intbaseWid = 1

    intcoreBool = op[c4d.ID_USERDATA,94]
    intcoreSize = op[c4d.ID_USERDATA,95]
    intcoreBevBool = op[c4d.ID_USERDATA,96]
    intcoreBevRad = op[c4d.ID_USERDATA,72]
    intconHgt = 0
    intconWid = 1
    intconBevBool = 0
    intconBevRad = 0
    intconBevConst = 0
    intcolNum = op[c4d.ID_USERDATA,101]
    intcolBool = op[c4d.ID_USERDATA,99]
    intcoltype = op[c4d.ID_USERDATA,100]
    intcolWid = op[c4d.ID_USERDATA,107]
    intcolDep = op[c4d.ID_USERDATA,108]
    intcolSides = op[c4d.ID_USERDATA,84]
    intcolSpShp = op[c4d.ID_USERDATA,110]
    intcolOffsetZ = op[c4d.ID_USERDATA,103]
    intcolOffsetX = op[c4d.ID_USERDATA,104]
    intcolMid = .5
    intcolNumDep = op[c4d.ID_USERDATA,102]
    intcolRot = op[c4d.ID_USERDATA,106]
    intcolBev = op[c4d.ID_USERDATA,74]
    intcolsubD = op[c4d.ID_USERDATA,109]
    intcolSpc  = op[c4d.ID_USERDATA,105]
    intstrBool = 0
    intnumStr = 0
    intstrHgt = 0
    intstrWid = 0


    #MATERIALS
#main glass
    MainGlassTexTag = op[c4d.ID_USERDATA,37]
    if MainGlassTexTag == None:
        MainGlassTexTag = c4d.BaseTag(c4d.Ttexture)
    if MainGlassTexTag.CheckType(13015):
        MainGlassTexTagC = c4d.BaseTag(c4d.Ttexture)
        MainGlassTexTagC[c4d.TEXTURETAG_MATERIAL] = MainGlassTexTag
        MainGlassTexTag = MainGlassTexTagC.GetClone()
    if MainGlassTexTag.CheckType(100004788):
        MainGlassTexTag = MainGlassTexTag.GetClone()

#mullion
    MulTexTag = op[c4d.ID_USERDATA,38]
    if MulTexTag == None:
        MulTexTag = c4d.BaseTag(c4d.Ttexture)
    if MulTexTag.CheckType(13015):
        MulTexTagC = c4d.BaseTag(c4d.Ttexture)
        MulTexTagC[c4d.TEXTURETAG_MATERIAL] = MulTexTag
        MulTexTag = MulTexTagC.GetClone()
    if MulTexTag.CheckType(100004788):
        MulTexTag = MulTexTag.GetClone()

#Concrete
    concreteTag = op[c4d.ID_USERDATA,39]
    if concreteTag == None:
        concreteTag = c4d.BaseTag(c4d.Ttexture)
    if concreteTag.CheckType(13015):
        concreteTagC = c4d.BaseTag(c4d.Ttexture)
        concreteTagC[c4d.TEXTURETAG_MATERIAL] = concreteTag
        concreteTag = concreteTagC.GetClone()
    if concreteTag.CheckType(100004788):
        concreteTag = concreteTag.GetClone()
    tTagCon = concreteTag
    tTagCol = concreteTag
#Core(base)
    tTagCore = op[c4d.ID_USERDATA,76]
    if tTagCore == None:
        tTagCore = c4d.BaseTag(c4d.Ttexture)
    if tTagCore.CheckType(13015):
        tTagCoreC = c4d.BaseTag(c4d.Ttexture)
        tTagCoreC[c4d.TEXTURETAG_MATERIAL] = tTagCore
        tTagCore = tTagCoreC.GetClone()
    if tTagCore.CheckType(100004788):
        tTagCore = tTagCore.GetClone()

#Stairs(base)
    tTagStr = op[c4d.ID_USERDATA,75]
    if tTagStr  == None:
        tTagStr  = c4d.BaseTag(c4d.Ttexture)
    if tTagStr .CheckType(13015):
        tTagStrC = c4d.BaseTag(c4d.Ttexture)
        tTagStrC[c4d.TEXTURETAG_MATERIAL] = tTagStr
        tTagStr = tTagStrC.GetClone()
    if tTagStr .CheckType(100004788):
        tTagStr  = tTagStr.GetClone()

#Roof
    tTagRoof = op[c4d.ID_USERDATA,77]
    if tTagRoof  == None:
        tTagRoof  = c4d.BaseTag(c4d.Ttexture)
    if tTagRoof .CheckType(13015):
        tTagRoofC = c4d.BaseTag(c4d.Ttexture)
        tTagRoofC[c4d.TEXTURETAG_MATERIAL] = tTagRoof
        tTagRoof = tTagRoofC.GetClone()
    if tTagRoof .CheckType(100004788):
        tTagRoof  = tTagRoof.GetClone()

#Interior Floor
    tTagIntFlr = intFlrTex = op[c4d.ID_USERDATA,80]
    if tTagIntFlr  == None:
        tTagIntFlr  = c4d.BaseTag(c4d.Ttexture)
    if tTagIntFlr .CheckType(13015):
        tTagIntFlrC = c4d.BaseTag(c4d.Ttexture)
        tTagIntFlrC[c4d.TEXTURETAG_MATERIAL] = tTagIntFlr
        tTagIntFlr = tTagIntFlrC.GetClone()
    elif tTagIntFlr .CheckType(100004788):
        tTagIntFlr  = tTagIntFlr.GetClone()


#Interior Core
    tTagIntCore = intCoreTex = op[c4d.ID_USERDATA,81]
    if tTagIntCore  == None:
        tTagIntCore  = c4d.BaseTag(c4d.Ttexture)
    if tTagIntCore .CheckType(13015):
        tTagIntCoreC = c4d.BaseTag(c4d.Ttexture)
        tTagIntCoreC[c4d.TEXTURETAG_MATERIAL] = tTagIntCore
        tTagIntCore = tTagIntCoreC.GetClone()
    if tTagIntCore .CheckType(100004788):
        tTagIntCore  = tTagIntCore.GetClone()

#Interior Columns
    tTagIntCol = intColTex = op[c4d.ID_USERDATA,82]
    if tTagIntCol == None:
        tTagIntCol = c4d.BaseTag(c4d.Ttexture)

    #multi block texture tags
    tex1 = op[c4d.ID_USERDATA,65]
    tex2 = op[c4d.ID_USERDATA,66]
    tex3 = op[c4d.ID_USERDATA,67]
    rtex = op[c4d.ID_USERDATA,68]

#   SET USER DATA LIMITS/Exceptions
    roofHgtY   = ((flrHgt*numFlrs)+(bevBot+bevTop)+roofSize/2+.1)
    if conSepBool == True and conSepHgt != 0:
        roofHgtY += conSepHgt*numFlrs
    roofHgt    = v(0,roofHgtY,0)
    robjhgt = roofHgt.y
    if baseBool == True: robjhgt+=baseHgt
    if rolCnt!=0 & rObjBool==True:
        for i in xrange(rolCnt):
            obj = rol.ObjectFromIndex(Adoc,i)
            obj.InserUnder(op)
            objrad = obj.GetRad()
            if obj!=None:
                origPos = obj.GetRelPos()
                obj.SetRelPos(v(origPos.x,robjhgt+(objrad.y),origPos.z))

    allUserdatas        = op.GetUserDataContainer()

    for descId, container in allUserdatas:
        # get the UserData id from 'descId'
        id              = descId[1].id

        if id == bevTopID:
            # BEVEL TOP LIMIT
            container[6]    = bevTopLim
            op.SetUserDataContainer(descId, container)
        if id == bevBotID:
            # BEVEL BOTTOM LIMIT
            container[6]    = bevBotLim
            op.SetUserDataContainer(descId, container)
        if id == bevRadID:
            # BEVEL BOTTOM LIMIT
            container[6]    = bevRadLim-5
            op.SetUserDataContainer(descId, container)

#hide/show menu elements
#-----------------------

    UD = op.GetUserDataContainer()

    for descId, container in UD:
       
        if descId[1].id == 73:   #num sides
            if coltype==1:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif coltype==3:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif coltype==4:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif coltype==5:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
        if descId[1].id == 84:      #num sides
            if intcoltype==1:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif intcoltype==3:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif intcoltype==4:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif intcoltype==5:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
#        if descId[1].id == 73:      #num sides
#            if intcoltype==1:
#                container[15] = False
#                op.SetUserDataContainer(descId, container)
#                c4d.EventAdd()
#            elif intcoltype==3:
#                container[15] = False
#                op.SetUserDataContainer(descId, container)
#                c4d.EventAdd()
#            elif intcoltype==4:
#                container[15] = False
#                op.SetUserDataContainer(descId, container)
#                c4d.EventAdd()
#            elif intcoltype==5:
#                container[15] = False
#                op.SetUserDataContainer(descId, container)
#                c4d.EventAdd()
#            else:
#                container[15] = True
#                op.SetUserDataContainer(descId, container)
#                c4d.EventAdd()
#        if descId[1].id == 85:      #midpoint
#            if intcoltype==3:
#                container[15] = False
#                op.SetUserDataContainer(descId, container)
#                c4d.EventAdd()
#            else:
#                container[15] = True
#                op.SetUserDataContainer(descId, container)
#                c4d.EventAdd()

        if descId[1].id == 86:      #midpoint
            if coltype==3:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()


        if descId[1].id == 83:      #midpoint
            if btype!=4:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 143:      #depth
            if coltype!=1:          #almost always active
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

#hide base spline number of sides unless its an nGon
        if descId[1].id == 154:      #midpoint
            if baseSplineType==1:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif baseSplineType==3:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif baseSplineType==4:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            elif baseSplineType==5:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 19:
            if bldgType==0:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 20:
            if bldgType==1:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 21:
            if bldgType==2:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 22:
            if bldgType==3:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()


        if descId[1].id == 24:
            if bldgType==4:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 83:
            if intBaseBool == False:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 30:
            if mulBool == False:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 118:
            if baseBool == False:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 14:
            if conSepBool == False:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 52:
            if roofBool == False:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()

        if descId[1].id == 64:
            if btype == 4:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
        if descId[1].id == 36:
            if btype != 4:
                container[15] = False
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
            else:
                container[15] = True
                op.SetUserDataContainer(descId, container)
                c4d.EventAdd()
#setMaxLimit for UD container
#----------------------------

#execute the main build function for the base



#material tag gen
    if(MainGlassTexTag!=None):
        if(MainGlassTexTag.CheckType(c4d.Mmaterial)):
            blanktagGlass = c4d.BaseTag(c4d.Ttexture)
            blanktagGlass.SetMaterial(MainGlassTexTag)
            blanktagGlass[c4d.TEXTURETAG_PROJECTION] = 3
            MainGlassTexTag = blanktagGlass.GetClone()
        elif(MainGlassTexTag.CheckType(c4d.Ttexture)):
            MainGlassTexTag = MainGlassTexTag
        else:
            blankTagIntCol = c4d.BaseTag(c4d.Ttexture)
            MainGlassTexTag= blankTagIntCol.GetClone()

    if(concreteTag!=None):
        if(concreteTag.CheckType(c4d.Mmaterial)):
            blanktagCon = c4d.BaseTag(c4d.Ttexture)
            blanktagCon.SetMaterial(concreteTag)
            blanktagCon[c4d.TEXTURETAG_PROJECTION] = 3
            concreteTag = blanktagCon.GetClone()

    if(MulTexTag!=None):
        if(MulTexTag.CheckType(c4d.Mmaterial)):
            blanktagMul = c4d.BaseTag(c4d.Ttexture)
            blanktagMul.SetMaterial(MulTexTag)
            blanktagMul[c4d.TEXTURETAG_PROJECTION] = 3
            MulTexTag = blanktagMul.GetClone()

    if(tTagRoof!=None):
        if(tTagRoof.CheckType(c4d.Mmaterial)):
            blankTagRoof = c4d.BaseTag(c4d.Ttexture)
            blankTagRoof.SetMaterial(tTagRoof)
            blankTagRoof[c4d.TEXTURETAG_PROJECTION] = 3
            newtTagRoof = blankTagRoof.GetClone()
        elif(tTagRoof.CheckType(c4d.Ttexture)):
            tTagRoof = tTagRoof.GetClone()
        else:
            blankTagtTagRoof = c4d.BaseTag(c4d.Ttexture)
            tTagIntCol= blankTagtTagRoof.GetClone()

    if(tTagCol!=None):
        if(tTagCol.CheckType(c4d.Mmaterial)):
            blankTagCol = c4d.BaseTag(c4d.Ttexture)
            blankTagCol.SetMaterial(tTagCol)
            blankTagCol[c4d.TEXTURETAG_PROJECTION] = 3
            tTagCol= blankTagCol.GetClone()
        elif(tTagCol.CheckType(c4d.Ttexture)):
            tTagCol = tTagCol.GetClone()
        else:
            blankTagCol = c4d.BaseTag(c4d.Ttexture)
            tTagCol= blankTagCol.GetClone()

    if(tTagIntCol!=None):
        if(tTagIntCol.CheckType(c4d.Mmaterial)):
            blankTagIntCol = c4d.BaseTag(c4d.Ttexture)
            blankTagIntCol.SetMaterial(tTagIntCol)
            blankTagIntCol[c4d.TEXTURETAG_PROJECTION] = 3
            tTagIntCol= blankTagIntCol.GetClone()
        elif(tTagIntCol.CheckType(c4d.Ttexture)):
            tTagIntCol = tTagIntCol.GetClone()
        else:
            blankTagIntCol = c4d.BaseTag(c4d.Ttexture)
            tTagIntCol= blankTagIntCol.GetClone()
    if(tTagIntFlr!=None):
        if(tTagIntFlr.CheckType(c4d.Mmaterial)):
            blankTagIntFlr = c4d.BaseTag(c4d.Ttexture)
            blankTagIntFlr.SetMaterial(tTagIntFlr)
            blankTagIntFlr[c4d.TEXTURETAG_PROJECTION] = 3
            tTagIntFlr= blankTagIntFlr.GetClone()
        elif(tTagIntFlr.CheckType(c4d.Ttexture)):
            tTagIntFlr = tTagIntFlr.GetClone()
        else:
            blankTagIntCol = c4d.BaseTag(c4d.Ttexture)
            tTagIntFlr= blankTagIntFlr.GetClone()
    if(tTagIntCore!=None):
        if(tTagIntCore.CheckType(c4d.Mmaterial)):
            blankTagIntCore = c4d.BaseTag(c4d.Ttexture)
            blankTagIntCore.SetMaterial(tTagIntCore)
            blankTagIntCore[c4d.TEXTURETAG_PROJECTION] = 3
            tTagIntCore= blankTagIntCore.GetClone()
        elif(tTagIntCore.CheckType(c4d.Ttexture)):
            tTagIntCore = tTagIntCore.GetClone()
        else:
            blankTagIntCol = c4d.BaseTag(c4d.Ttexture)
            tTagIntCore= blankTagIntCore.GetClone()

#--------Basic C4D Object Construction-------------#

    flrNull       = c4d.BaseObject(c4d.Onull)#create null for floor
    mainNull       = c4d.BaseObject(c4d.Onull)#create Main null
    flrCloner = c4d.BaseObject(1018544)#cloner
    baseSpline   = BaseSpline(btype,width,depth,
                                bevBool,bevRadius,
                                sSubD,sSubDType,sSubDAngle,numSides,sSubDLen,
                                sliceMax,sliceMin,sliceBool,
                                innerBool,inOffsetSqr,
                                innerBoolNside,innerOffsetNside,
                                pST,pS,pT)


#---------If MultiBlock is turned on, then make that-----------#
    if btype == 4:
        mBObject = MultiBlock(numBlocks,numFlrs,width,depth,height,rOff,eList,
                            tex1,tex2,tex3,rtex,seed,bDist,
                            bevBool, bevRadius,
                            sSubD, sSubDType, sSubDAngle, sSubDLen)
        mBObject.InsertUnder(mainNull)
        mainNull.SetRelScale(mainScale)
        return mainNull

#---------otherwise create the Base Building Spline BBS---------#
    else:
        bSpline1   = BaseSpline(btype,width,depth,
                                bevBool,bevRadius,
                                sSubD,sSubDType,sSubDAngle,numSides,sSubDLen,
                                sliceMax,sliceMin,sliceBool,
                                innerBool,inOffsetSqr,
                                innerBoolNside,innerOffsetNside,
                                pST,pS,pT)
        bSpline2 = bSpline1.GetClone()#baseSplineCopy for floors
        bSpline3 = bSpline1.GetClone()
    #-----------CREATE THE MAIN BUILDING--------------#
   
        flrObj = FloorExtrudeObj(bSpline1, flrHgt, numFlrs, bevTop, bevBot,mainfx,False)

        if(flrBase == True)&op[c4d.ID_USERDATA,88] == True:
            flrBaseObj = Roof(rtype, flrHgt, numFlrs, 1, True)
            flrBaseHgt = (flrHgt/2)-(bevBot/2)-(bevTop/2)
            bSpline3.InsertUnder(flrBaseObj)
            flrBaseObj.InsertUnder(flrNull)
            flrBaseObj.SetRelPos(c4d.Vector(0,flrBaseHgt,0))
            fboX = (bevBot/width)
            fboZ = (bevBot/depth)
            flrBaseObj.SetRelScale(c4d.Vector(1+fboX,1,1+fboZ))
            flrBaseObj.InsertTag(tTagIntFlr)



        flrCopy = flrObj.GetClone()
        flrCloner[c4d.MGCLONER_VOLUMEINSTANCES] = instBool
        flrCloner[c4d.MG_LINEAR_COUNT] = numFlrs
        flrCloner[c4d.MG_LINEAR_OBJECT_POSITION,c4d.VECTOR_Y] = flrHgt+.01
        flrCloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] = mainfx
        flrObj.InsertUnder(flrNull)
   
        if mulWidth != 0:
            if mulBool == True:
                mul = Mullion(flrCopy,mulWidth,mulPBool,mulSubD)
                if mulPBool == False:
                    mulPtag = mul.InsertTag(c4d.Tphong)
                    mulPtag[c4d.PHONGTAG_PHONG_ANGLELIMIT] = 1
                    mulPtag[c4d.PHONGTAG_PHONG_ANGLE] = 0

                if MulTexTag != None:
                    if(MulTexTag.CheckType(c4d.Ttexture)):
                        mul.InsertTag(MulTexTag.GetClone())
                    elif(MulTexTag.CheckType(c4d.Mmaterial)):
                        mul.InsertTag(newMulTexTag.GetClone())
                mul.InsertUnder(flrNull)
        if MainGlassTexTag != None:
            flrObj.InsertTag(MainGlassTexTag.GetClone())
        flrNull.InsertUnder(flrCloner)
       
        flrCloner.SetRelPos(c4d.Vector(0,(bevBot-flrHgt/2)+conBevRad,0))
        flrCloner.InsertUnder(mainNull)
        mNull_y = (mainScale.y)-(flrHgt-bevBot+bevTop)/2+mulWidth+bevBot+bevTop
        if conBevBool == True:
            mNull_y += conBevRad

        mainNull.SetRelScale(mainScale)
        if baseBool == True:
            if (btype!=4):
                    buildingBase = BuildingBase(baseBool,baseSplineType,baseHgt,baseWid,baseNumSid,
                            conHgt,conWid,conBevBool,conBevRad,conBevConst,
                            coreBool,coreSize,coreBevBool,coreBevRad,
                     colBool,colType,colNum,colNumDep,colWid,colDep,colSides,
                                colSpShp,colOffsetZ,colOffsetX,colRot,colMid,colsubD,colSpc,
                     strBool,numStr,strHgt,strWid,strScale,baseSpline,
                            tTagCon,tTagCore,tTagStr)
                    mainNull[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] += baseHgt
                    buildingBase.InsertUnder(mainNull)
                    buildingBase[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] -=baseHgt
        if conSepBool == True:
                conSepNull = bo(c4d.Onull)
                spConSep = bSpline1.GetClone()
                spConSep.SetRelPos(v(0,conSepHgt+flrHgt,0))
                spConSep.SetRelScale(v(1.02,1,1.02))
                conSep = FloorExtrudeObj(spConSep, conSepHgt, numFlrs, 0, 0,mainfx, False)

                flrCloner[c4d.MG_LINEAR_OBJECT_POSITION,c4d.VECTOR_Y] = flrHgt+conSepHgt+.01
                conSep.InsertUnder(conSepNull)
                conSepNull.InsertUnder(flrNull)
                conSepNull.SetRelPos(v(0,0,0))
                if concreteTag != None:
                   
                    if(concreteTag.CheckType(c4d.Mmaterial)):
                        blanktagConSep = c4d.BaseTag(c4d.Ttexture)
                        blanktagConSep.SetMaterial(concreteTag)
                        blanktagConSep [c4d.TEXTURETAG_PROJECTION] = 3
                        concreteSepTag = blanktagConSep.GetClone()
                        conSep.InsertTag(concreteSepTag.GetClone())
                    elif(concreteTag.CheckType(c4d.Ttexture)):
                        conSep.InsertTag(concreteTag.GetClone())
                else:
                    conSep.InsertTag(c4d.BaseTag(c4d.Ttexture))
                c4d.EventAdd()

        if (roofBool == True)&(roofSize!=0):
                roofObj = Roof(rtype, flrHgt, numFlrs, roofSize, rcBool)
                bSpline2.InsertUnder(roofObj)
                roofObj.InsertUnder(mainNull)
                roofObj.SetRelPos(roofHgt)
                if rObjBool == True:
                    HiderNull = bo(c4d.Onull)
                    HiderNull.InsertUnder(mainNull)
                    rObjCloner = bo(1018544)
                    rObjConnector = bo(1011010)
                    rObjConnector.InsertUnder(HiderNull)
                    HiderNull[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1
                    HiderNull[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1
                    rObjLink = roofObj.GetClone()
                    rObjLink[c4d.CAP_TYPE] = 2
                    rObjLink[c4d.CAP_REGULAR] = True
                    rObjLink[c4d.CAP_REGULARWIDTH] = 10/rNumObj
                    rObjLink.InsertUnder(rObjConnector)
                    for obj in rol:
                        obj.SetRelPos(roofHgt)
                    if ventsBool == True:
                        robj1Null = bo(c4d.Onull)
                        robj1 = bo(c4d.Ocube)
                       
                        robj1Len = robj1[c4d.PRIM_CUBE_LEN] = v(100,100,100)
                        robj1.InsertUnder(robj1Null)
                        robj1.SetRelPos(v(0,robj1Len.y/2,0))
                        robj1Null.InsertUnder(rObjCloner)
                    rObjCloner.SetRelPos(roofHgt)
                   
                    rObjCloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 0

                    rObjCloner[c4d.MG_OBJECT_LINK] = rObjConnector
                    rObjCloner[c4d.MG_POLY_SELECTION] = 6
                    rObjCloner[c4d.MG_POLY_MODE_] = 3
                    rObjCloner[c4d.MG_POLYSURFACE_COUNT] = rNumObj
                    rObjCloner.InsertUnder(mainNull)
#                    rObjConnector.SetRelScale(v(.8,1,.8))
                   
                if tTagRoof != None:
                    if(tTagRoof.CheckType(c4d.Ttexture)):
                        roofObj.InsertTag(tTagRoof.GetClone())
                    elif(tTagRoof.CheckType(c4d.Mmaterial)):
                        roofObj.InsertTag(newtTagRoof.GetClone())
                    else:
                        roofObj.InsertTag(c4d.BaseTag(Ttexture))

                roofObj.SetRelScale(v(1*roofScale.x,1*roofScale.y,1*roofScale.z))
                c4d.EventAdd()

        if(btype == 3):
            pass
        else:
            flrCloner.SetRelPos(c4d.Vector(0,mNull_y,0))
        if intBaseBool == True:
                intFlr = BuildingBase(1,6,flrHgt+conSepHgt,1,3,
                            intconHgt,0,intconBevBool,intconBevRad,intconBevConst,
                            intcoreBool,intcoreSize,intcoreBevBool,intcoreBevRad,
                     intcolBool,intcoltype,intcolNum,intcolNumDep,intcolWid,intcolDep,intcolSides,
                            intcolSpShp,intcolOffsetZ,intcolOffsetX,intcolRot,intcolMid,intcolsubD,intcolSpc,
                     0,numStr,strHgt,strWid,strScale,baseSpline,
                            tTagIntCol,tTagIntCore,None)

                intFlr.SetRelPos(v(0,0,0))
                intFlr.InsertUnder(flrNull)
       
#base gen
       
    return mainNull
    EventAdd()