예제 #1
0
 def _execute(self, context):
     self.file = IfcStore.get_file()
     props = get_pset_props(context, self.obj, self.obj_type)
     ifc_definition_id = get_pset_obj_ifc_definition_id(
         context, self.obj, self.obj_type)
     ifcopenshell.api.run(
         "pset.remove_pset",
         self.file,
         **{
             "product": self.file.by_id(ifc_definition_id),
             "pset": self.file.by_id(self.pset_id),
         },
     )
     Data.load(IfcStore.get_file(), ifc_definition_id)
예제 #2
0
    def _execute(self, context):
        self.file = IfcStore.get_file()
        props = get_pset_props(context, self.obj, self.obj_type)
        ifc_definition_id = get_pset_obj_ifc_definition_id(
            context, self.obj, self.obj_type)
        properties = {}

        pset_id = self.pset_id or props.active_pset_id
        if self.properties:
            properties = json.loads(self.properties)
        else:
            data = Data.psets if pset_id in Data.psets else Data.qtos
            for prop in props.properties:
                properties[prop.name] = prop.get_value()

        if pset_id in Data.psets:
            ifcopenshell.api.run(
                "pset.edit_pset",
                self.file,
                **{
                    "pset":
                    self.file.by_id(pset_id),
                    "name":
                    props.active_pset_name,
                    "properties":
                    properties,
                    "pset_template":
                    blenderbim.bim.schema.ifc.psetqto.get_by_name(
                        props.active_pset_name),
                },
            )
        else:
            for key, value in properties.items():
                if isinstance(value, float):
                    properties[key] = round(value, 4)
            ifcopenshell.api.run(
                "pset.edit_qto",
                self.file,
                **{
                    "qto": self.file.by_id(pset_id),
                    "name": props.active_pset_name,
                    "properties": properties,
                },
            )
            CostData.purge()
        Data.load(IfcStore.get_file(), ifc_definition_id)
        bpy.ops.bim.disable_pset_editing(obj=self.obj, obj_type=self.obj_type)
예제 #3
0
def get_resource_quantity_names(self, context):
    global resourcequantitynames_enum
    global resourcequantitynames_id
    ifc_file = IfcStore.get_file()
    active_resource_index = context.scene.BIMResourceProperties.active_resource_index
    total_resources = len(context.scene.BIMResourceTreeProperties.resources)
    if not total_resources or active_resource_index >= total_resources:
        return []
    ifc_definition_id = context.scene.BIMResourceTreeProperties.resources[active_resource_index].ifc_definition_id
    if resourcequantitynames_id != ifc_definition_id:
        resourcequantitynames_enum = []
        resourcequantitynames_id = ifc_definition_id
        names = set()
        if ifc_definition_id not in PsetData.products:
            PsetData.load(ifc_file, ifc_definition_id)
        for qto_id in PsetData.products[ifc_definition_id]["qtos"]:
            qto = PsetData.qtos[qto_id]
            [names.add(PsetData.properties[p]["Name"]) for p in qto["Properties"]]
        resourcequantitynames_enum.extend([(n, n, "") for n in names])
    return resourcequantitynames_enum
예제 #4
0
def get_process_quantity_names(self, context):
    global processquantitynames_enum
    global processquantitynames_id
    ifc_file = IfcStore.get_file()
    active_task_index = context.scene.BIMWorkScheduleProperties.active_task_index
    total_tasks = len(context.scene.BIMTaskTreeProperties.tasks)
    if not total_tasks or active_task_index >= total_tasks:
        return []
    ifc_definition_id = context.scene.BIMTaskTreeProperties.tasks[active_task_index].ifc_definition_id
    if processquantitynames_id != ifc_definition_id:
        processquantitynames_enum = []
        processquantitynames_id = ifc_definition_id
        names = set()
        if ifc_definition_id not in PsetData.products:
            PsetData.load(ifc_file, ifc_definition_id)
        for qto_id in PsetData.products[ifc_definition_id]["qtos"]:
            qto = PsetData.qtos[qto_id]
            [names.add(PsetData.properties[p]["Name"]) for p in qto["Properties"]]
        processquantitynames_enum.extend([(n, n, "") for n in names])
    return processquantitynames_enum
예제 #5
0
def getPsetNames(self, context):
    global psetnames
    obj = context.active_object
    if not obj.BIMObjectProperties.ifc_definition_id:
        return []
    if obj.BIMObjectProperties.ifc_definition_id not in Data.products:
        Data.load(IfcStore.get_file(),
                  obj.BIMObjectProperties.ifc_definition_id)
    element = IfcStore.get_file().by_id(
        obj.BIMObjectProperties.ifc_definition_id)
    ifc_class = element.is_a()
    if ifc_class not in psetnames:
        psets = blenderbim.bim.schema.ifc.psetqto.get_applicable(
            ifc_class, pset_only=True)
        psetnames[ifc_class] = [(p.Name, p.Name, "") for p in psets]
    assigned_names = [
        Data.psets[p]["Name"] for p in Data.products[
            obj.BIMObjectProperties.ifc_definition_id]["psets"]
    ]
    return [p for p in psetnames[ifc_class] if p[0] not in assigned_names]
예제 #6
0
 def _execute(self, context):
     self.file = IfcStore.get_file()
     pset_name = get_pset_props(context, self.obj, self.obj_type).pset_name
     if self.obj_type == "Object":
         objects = [o.name for o in context.selected_objects]
     else:
         objects = [self.obj]
     for obj in objects:
         ifc_definition_id = get_pset_obj_ifc_definition_id(
             context, obj, self.obj_type)
         if not ifc_definition_id:
             continue
         element = tool.Ifc.get().by_id(ifc_definition_id)
         if pset_name in blenderbim.bim.schema.ifc.psetqto.get_applicable_names(
                 element.is_a(), pset_only=True):
             ifcopenshell.api.run("pset.add_pset",
                                  self.file,
                                  product=element,
                                  name=pset_name)
             Data.load(IfcStore.get_file(), ifc_definition_id)
예제 #7
0
def get_product_quantity_names(self, context):
    global productquantitynames_enum
    global productquantitynames_count
    ifc_file = IfcStore.get_file()
    total_selected_objects = len(context.selected_objects)
    if total_selected_objects != productquantitynames_count or total_selected_objects == 1:
        productquantitynames_enum = []
        productquantitynames_count = total_selected_objects
        names = set()
        for obj in context.selected_objects:
            element_id = obj.BIMObjectProperties.ifc_definition_id
            if not element_id:
                continue
            potential_names = set()
            if element_id not in PsetData.products:
                PsetData.load(ifc_file, element_id)
            for qto_id in PsetData.products[element_id]["qtos"]:
                qto = PsetData.qtos[qto_id]
                [potential_names.add(PsetData.properties[p]["Name"]) for p in qto["Properties"]]
            names = names.intersection(potential_names) if names else potential_names
        productquantitynames_enum.extend([(n, n, "") for n in names])
    return productquantitynames_enum
예제 #8
0
파일: task.py 프로젝트: Krande/IfcOpenShell
def calculate_quantities(usecase_path, ifc_file, settings):
    if not set(["ScheduleStart", "ScheduleFinish", "ScheduleDuration"
                ]).intersection(set(settings["attributes"].keys())):
        return
    element = settings["task_time"]
    if not element.ScheduleDuration:
        return
    task = [e for e in ifc_file.get_inverse(element) if e.is_a("IfcTask")][0]
    qto = ifcopenshell.api.run("pset.add_qto",
                               ifc_file,
                               should_run_listeners=False,
                               product=task,
                               name="Qto_TaskBaseQuantities")
    ifcopenshell.api.run(
        "pset.edit_qto",
        ifc_file,
        should_run_listeners=False,
        qto=qto,
        properties={
            "StandardWork":
            ifcopenshell.util.date.ifc2datetime(element.ScheduleDuration).days,
        },
    )
    PsetData.load(ifc_file, task.id())
예제 #9
0
파일: slab.py 프로젝트: Krande/IfcOpenShell
def calculate_quantities(usecase_path, ifc_file, settings):
    unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file)
    obj = settings["blender_object"]
    product = ifc_file.by_id(obj.BIMObjectProperties.ifc_definition_id)
    parametric = ifcopenshell.util.element.get_psets(product).get(
        "EPset_Parametric")
    if not parametric or parametric["Engine"] != "BlenderBIM.DumbLayer3":
        return
    qto = ifcopenshell.api.run("pset.add_qto",
                               ifc_file,
                               should_run_listeners=False,
                               product=product,
                               name="Qto_SlabBaseQuantities")
    length = obj.dimensions[0] / unit_scale
    width = obj.dimensions[1] / unit_scale
    depth = obj.dimensions[2] / unit_scale

    perimeter = 0
    helper = Helper(ifc_file)
    indices = helper.auto_detect_arbitrary_profile_with_voids_extruded_area_solid(
        settings["geometry"])

    bm = bmesh.new()
    bm.from_mesh(settings["geometry"])
    bm.verts.ensure_lookup_table()

    def calculate_profile_length(indices):
        indices.append(indices[0])  # Close the loop
        edge_vert_pairs = list(zip(indices, indices[1:]))
        return sum([(bm.verts[p[1]].co - bm.verts[p[0]].co).length
                    for p in edge_vert_pairs])

    perimeter += calculate_profile_length(indices["profile"])
    for inner_indices in indices["inner_curves"]:
        perimeter += calculate_profile_length(inner_indices)

    bm.free()

    if product.HasOpenings:
        # TODO: calculate gross / net
        gross_area = 0
        net_area = 0
        gross_volume = 0
        net_volume = 0
    else:
        bm = bmesh.new()
        bm.from_object(obj, bpy.context.evaluated_depsgraph_get())
        bm.faces.ensure_lookup_table()
        gross_area = sum([f.calc_area() for f in bm.faces if f.normal.z > 0.9])
        net_area = gross_area
        gross_volume = bm.calc_volume()
        net_volume = gross_volume
        bm.free()

    properties = {
        "Depth": round(depth, 2),
        "Perimeter": round(perimeter, 2),
        "GrossArea": round(gross_area, 2),
        "NetArea": round(net_area, 2),
        "GrossVolume": round(gross_volume, 2),
        "NetVolume": round(net_volume, 2),
    }

    if round(obj.dimensions[0] * obj.dimensions[1] * obj.dimensions[2],
             2) == round(gross_volume, 2):
        properties.update({
            "Length": round(length, 2),
            "Width": round(width, 2),
        })
    else:
        properties.update({
            "Length": None,
            "Width": None,
        })

    ifcopenshell.api.run("pset.edit_qto",
                         ifc_file,
                         should_run_listeners=False,
                         qto=qto,
                         properties=properties)
    PsetData.load(ifc_file, obj.BIMObjectProperties.ifc_definition_id)