mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
You can now modify project context declarations for project libraries, denoting which assets are part of the library
This commit is contained in:
@@ -129,7 +129,10 @@ class IfcExporter:
|
||||
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
element_collection = bpy.data.collections.get(obj.name)
|
||||
|
||||
if element.is_a("IfcProject"):
|
||||
if self.file.schema == "IFC2X3":
|
||||
if element.is_a("IfcProject"):
|
||||
return
|
||||
elif element.is_a("IfcContext"):
|
||||
return
|
||||
|
||||
if (element.is_a("IfcElement") and element_collection) or element.is_a("IfcSpatialStructureElement"):
|
||||
|
||||
@@ -9,6 +9,9 @@ classes = (
|
||||
operator.ChangeLibraryElement,
|
||||
operator.RefreshLibrary,
|
||||
operator.RewindLibrary,
|
||||
operator.AssignLibraryDeclaration,
|
||||
operator.UnassignLibraryDeclaration,
|
||||
operator.SaveLibraryFile,
|
||||
prop.LibraryElement,
|
||||
prop.BIMProjectProperties,
|
||||
ui.BIM_PT_project,
|
||||
|
||||
@@ -5,8 +5,6 @@ import ifcopenshell.api
|
||||
import bpy
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
|
||||
# from ifcopenshell.api.project.data import Data
|
||||
|
||||
|
||||
class CreateProject(bpy.types.Operator):
|
||||
bl_idname = "bim.create_project"
|
||||
@@ -149,6 +147,10 @@ class ChangeLibraryElement(bpy.types.Operator):
|
||||
new = self.props.library_elements.add()
|
||||
new.name = element.Name or "Unnamed"
|
||||
new.ifc_definition_id = element.id()
|
||||
if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"):
|
||||
new.is_declared = False
|
||||
elif element.HasContext and element.HasContext[0].RelatingContext.is_a("IfcProjectLibrary"):
|
||||
new.is_declared = True
|
||||
else:
|
||||
for ifc_class in ifc_classes:
|
||||
new = self.props.library_elements.add()
|
||||
@@ -169,5 +171,52 @@ class RewindLibrary(bpy.types.Operator):
|
||||
element_name = self.props.library_breadcrumb[total_breadcrumbs - 2].name
|
||||
self.props.library_breadcrumb.remove(total_breadcrumbs - 1)
|
||||
self.props.library_breadcrumb.remove(total_breadcrumbs - 2)
|
||||
bpy.ops.bim.change_library_element(element_name=element_name)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AssignLibraryDeclaration(bpy.types.Operator):
|
||||
bl_idname = "bim.assign_library_declaration"
|
||||
bl_label = "Assign Library Declaration"
|
||||
definition: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.props = context.scene.BIMProjectProperties
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration",
|
||||
IfcStore.library_file,
|
||||
definition=IfcStore.library_file.by_id(self.definition),
|
||||
relating_context=IfcStore.library_file.by_type("IfcProjectLibrary")[0],
|
||||
)
|
||||
element_name = self.props.active_library_element
|
||||
bpy.ops.bim.rewind_library()
|
||||
bpy.ops.bim.change_library_element(element_name = element_name)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class UnassignLibraryDeclaration(bpy.types.Operator):
|
||||
bl_idname = "bim.unassign_library_declaration"
|
||||
bl_label = "Unassign Library Declaration"
|
||||
definition: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.props = context.scene.BIMProjectProperties
|
||||
ifcopenshell.api.run(
|
||||
"project.unassign_declaration",
|
||||
IfcStore.library_file,
|
||||
definition=IfcStore.library_file.by_id(self.definition),
|
||||
relating_context=IfcStore.library_file.by_type("IfcProjectLibrary")[0],
|
||||
)
|
||||
element_name = self.props.active_library_element
|
||||
bpy.ops.bim.rewind_library()
|
||||
bpy.ops.bim.change_library_element(element_name = element_name)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class SaveLibraryFile(bpy.types.Operator):
|
||||
bl_idname = "bim.save_library_file"
|
||||
bl_label = "Save Library File"
|
||||
|
||||
def execute(self, context):
|
||||
IfcStore.library_file.write(IfcStore.library_path)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -16,6 +16,7 @@ from bpy.props import (
|
||||
class LibraryElement(PropertyGroup):
|
||||
name: StringProperty(name="Name")
|
||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||
is_declared: BoolProperty(name="Is Declared", default=False)
|
||||
|
||||
|
||||
class BIMProjectProperties(PropertyGroup):
|
||||
|
||||
@@ -81,6 +81,9 @@ class BIM_PT_project_library(Panel):
|
||||
self.props = context.scene.BIMProjectProperties
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text=IfcStore.library_path or "No Library Loaded", icon="ASSET_MANAGER")
|
||||
if IfcStore.library_file:
|
||||
row.label(text=IfcStore.library_file.schema)
|
||||
row.operator("bim.save_library_file", text="", icon="EXPORT")
|
||||
row.operator("bim.select_library_file", icon="FILE_FOLDER", text="")
|
||||
if IfcStore.library_file:
|
||||
self.draw_library_ul()
|
||||
@@ -113,3 +116,15 @@ class BIM_UL_library(UIList):
|
||||
op = row.operator("bim.change_library_element", text="", icon="DISCLOSURE_TRI_RIGHT", emboss=False)
|
||||
op.element_name = item.name
|
||||
row.label(text=item.name)
|
||||
if (
|
||||
not item.ifc_definition_id
|
||||
or IfcStore.library_file.schema == "IFC2X3"
|
||||
or not IfcStore.library_file.by_type("IfcProjectLibrary")
|
||||
):
|
||||
return
|
||||
if item.is_declared:
|
||||
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
|
||||
op.definition = item.ifc_definition_id
|
||||
else:
|
||||
op = row.operator("bim.assign_library_declaration", text="", icon="KEYFRAME", emboss=False)
|
||||
op.definition = item.ifc_definition_id
|
||||
|
||||
Reference in New Issue
Block a user