[quickload_model] r'd = \jakob\teaching\7m900_fundamentals_of_bim\2016_2017\assignment_B1\7m900_tue_hello_wall_with_door.ifc' [snippets] print all wall ids = ########################################################################### |# A simple script that iterates over all walls in the current model # |# and prints their Globally unique IDs (GUIDS) to the console window # |########################################################################### | |for wall in model.by_type("IfcWall"): | print ("wall with global id: "+str(wall.GlobalId)) | print properties of current selection = ########################################################################### |# A simple script that iterates over all IfcPropertySets of the currently # |# selected object and prints them to the console # |########################################################################### | |# check if something is selected |if selection: | #get the IfcProduct that is stored in the global variable 'selection' | obj = selection | for relDefinesByProperties in obj.IsDefinedBy: | print("[{0}]".format(relDefinesByProperties.RelatingPropertyDefinition.Name)) | for prop in relDefinesByProperties.RelatingPropertyDefinition.HasProperties: | print ("{:<20} :{}".format(prop.Name,prop.NominalValue.wrappedValue)) | print ("\\n") | asdfasdf = ########################################################################### |# A simple script that iterates over all walls in the current model # |# and prints their Globally unique IDs (GUIDS) to the console window # |########################################################################### | |for wall in model.by_type("IfcWall"): | print ("wall with global id: "+str(wall.GlobalId)) | get all selected products = print (viewer.get_selection_set(model)) | hightlight all selected products = sel = viewer.get_selection_set(model) |for p in sel: | viewer.set_color(p,1,0,1) save properties to csv = ########################################################################### |# A simple script that iterates over all IfcPropertySets of the currently # |# selected object and prints them to the console # |########################################################################### |import csv |# check if something is selected |sel_set = viewer.get_selection_set(model) | #get the IfcProduct that is stored in the global variable 'selection' |with open(r'D:\\test1.csv', 'wb') as testfile: | for p in sel_set: | | csv_writer = csv.writer(testfile) | for relDefinesByProperties in p.IsDefinedBy: | print("[{0}]".format(relDefinesByProperties.RelatingPropertyDefinition.Name)) | for prop in relDefinesByProperties.RelatingPropertyDefinition.HasProperties: | print ("{:<20} :{}".format(prop.Name,prop.NominalValue.wrappedValue)) | print ("\\n") | csv_writer.writerow([p.GlobalId, p.Name, relDefinesByProperties.RelatingPropertyDefinition.Name,prop.Name,prop.NominalValue.wrappedValue]) | | | print project information = project = model.by_type("IfcProject") |print (project[0].Name) |print (project[0].GlobalId) |print (project[0].Description) |print (project[0].LongName) get model object by guid = project = model.by_guid('0YvctVUKr0kugbFTf53O9L') |print (project.Name) all attribute names of an instance = project = model.by_type("IfcProject")[0] |for att_idx in range(0,len(project)): | print(project.attribute_name(att_idx)) | all attribute names, values and types = door = model.by_type("IfcDoor")[0] |for att_idx in range(0,len(project)-1): | field_width = 20 | # In case we are dealing with a different IFC version | # there might by attributes that do not exist in a 2x3 file | # handle the attempt to print out a value where there is no | # attribute gracefully | try: | att_name = door.attribute_name(att_idx) | att_type = door.attribute_type(att_name) | att_value = door[att_name] | print("{}\\t{}\\t{}".format(att_name.ljust(field_width),att_type.ljust(field_width), att_value)) | except: | pass | mark selection red = products = viewer.get_selection_set(model) |for product in products: | viewer.set_color(product, 0.8,0,0) add properties to selected object = import ifcopenshell |import uuid |if selection: | product = selection | prop_set_guid = ifcopenshell.guid.compress(uuid.uuid1().hex) | property_values = [ | model.createIfcPropertySingleValue("My own property", "Description of My Own Property", model.create_entity("IfcText", "some textual Value"), None), | model.createIfcPropertySingleValue("isMadeUp", "whether or not this is a made up valeue", model.create_entity("IfcBoolean", True), None), | ] | property_set = model.createIfcPropertySet(prop_set_guid, product.OwnerHistory, "MyOwnPropSet", None, property_values) | rel_guid = ifcopenshell.guid.compress(uuid.uuid1().hex) | model.createIfcRelDefinesByProperties(rel_guid, product.OwnerHistory, None, None, [product], property_set) | |model.write(r'D:\\properties_added.ifc') |print("writing done") minimalistic model checker = ########################################################################### |# Minimalistic Model checker script |# A simple to use external information defined in e.g. Excel to check |# values in an IFC file. Create a minimal CSV like: |# |# Element;Attribute;Min_height |# IfcDoor;OverallHeight;2.1 |# IfcWindow;OverallHeight;1 |# |# and save it to a convient location |########################################################################### |import csv |#open the file |with open(r'D:\\simple_check.csv') as checkfile: | # create a reader, that reads the columns into a dictionary | # using the first row as keys ("Element", "Attribute", "Min_height" | reader = csv.DictReader(checkfile,delimiter=";") | # iterate over all rows | for row in reader: | print(row['Element'], row["Attribute"],row['Min_height']) | # get all elements | for element in model.by_type(row["Element"]): | attribute_value=element[row["Attribute"]] | if float(attribute_value) < float(row['Min_height']): | print ("Element {} violates the minimum height requirement with {}".format(element.GlobalId,attribute_value)) | | | |