"Check none data concrete footing in Model \n\n\n Updated : 01-05-2024 \n\n Shared by : TUMCIVIL"
__author__ = 'TUMCIVIL'
__version__ = '1.0.0'
__title__ = ' Check none data concrete footing'
# for timing -------------------------------------------------------------------
import pyrevit.coreutils as cor
from pyrevit.coreutils import Timer
timer = Timer()
# ------------------------------------------------------------------------------
import sys
import re
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB.Structure import *
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument


def checkParameter(parameter):
    storageType = parameter.StorageType
    if (storageType.ToString() == "ElementId"):
        value = parameter.AsValueString()
    return value




if __name__ == '__main__':
    foundations = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_StructuralFoundation) \
        .WhereElementIsNotElementType() \
        .ToElements()

    if len(foundations)!= 0:
        out = []
        rows = 0
        familyType = []
        for e in foundations:
                p2 = []
                id = e.Id
                name1 = e.Name
                family2 = e.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM)
                value2 = checkParameter(family2)
                if value2 != "Wall Foundation" and value2 != "Foundation Slab" and bool(re.match("Pile", name1)) == False:
                    nameFooting = e.LookupParameter("Name Footing").AsString()
                    size = e.LookupParameter("Size").AsString()
                    location = e.LookupParameter("Location").AsString()
                    strengthCon = e.LookupParameter("Strength Concrete").AsString()
                    namePile = e.LookupParameter("Name Pile").AsString()

                    p2.append(id)  # Id 0
                    p2.append(name1)  # Name 1
                    p2.append(nameFooting)  # Name Footing 2
                    p2.append(size)  # size 3
                    p2.append(location)  # Location 4
                    p2.append(strengthCon)  # Stength Concrete 5
                    p2.append(namePile)  # Name Pile 6

                    out.append(p2)

            
        # print("out= {}".format(out))
        print("1   :  UNDERGROUND-STRUCTURE WORKS")
        print("====" * 20)

        # k = [v for v in out if (v[2] == None or v[3] == None or v[4] == None or v[5] == None or v[6] == None) and bool(re.match("Pile",v[1])) == False]
        k = [v for v in out if (v[2] == None or v[2] == "" or v[3] == None or v[3] == "" or v[4] == None or v[4] == "" or v[5] == None or v[5] == "" or v[6] == None or v[6] == "") and bool(re.match("Pile",v[1])) == False]
        nk = len(k)
        print("Reports Warning!")
        print("Concrete Footing :")
        print("None data = {} items".format(nk))
        if nk != 0:
            for i in k:
                print("Id = {}".format(i[0]))
            print("Remark : this results excluded none data Wall Foundation and Foundation Slab")
        else:
            print("Completed; Good job!")
            print("Remark : this results excluded Wall Foundation and Foundation Slab")
        # sys.exit()
    else:
        print ("***None Footing in Model***")


# for timing -------------------------------------------------------------------
print("====" * 20)
endtime = timer.get_time()
print("Time been used = {} sec.".format(endtime))
currentDate = cor.current_date()
currentTime = cor.current_time()
print ("Date : {} ; {}".format(currentDate,currentTime))
print ("Credited by : {}".format(__author__))
print("====" * 20)
# ------------------------------------------------------------------------------