mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
bonsai - bim.append_library_element option to skip reusing materials by name
Example - https://imgur.com/PsAPugJ
This commit is contained in:
@@ -28,6 +28,7 @@ import datetime
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.api.project
|
||||||
import ifcopenshell.util.file
|
import ifcopenshell.util.file
|
||||||
import ifcopenshell.util.selector
|
import ifcopenshell.util.selector
|
||||||
import ifcopenshell.util.geolocation
|
import ifcopenshell.util.geolocation
|
||||||
@@ -425,9 +426,15 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_idname = "bim.append_library_element"
|
bl_idname = "bim.append_library_element"
|
||||||
bl_label = "Append Library Element"
|
bl_label = "Append Library Element"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
bl_description = "Append element to the current project"
|
bl_description = (
|
||||||
|
"Append element to the current project.\n\n"
|
||||||
|
"ALT+CLICK to skip reusing materials, profiles, styles based on their name (may result in duplicates)"
|
||||||
|
)
|
||||||
definition: bpy.props.IntProperty()
|
definition: bpy.props.IntProperty()
|
||||||
prop_index: bpy.props.IntProperty()
|
prop_index: bpy.props.IntProperty()
|
||||||
|
assume_unique_by_name: bpy.props.BoolProperty(name="Assume Unique By Name", default=True, options={"SKIP_SAVE"})
|
||||||
|
|
||||||
|
file: ifcopenshell.file
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
@@ -436,13 +443,20 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
cls.poll_message_set("Please create or load a project first.")
|
cls.poll_message_set("Please create or load a project first.")
|
||||||
return poll
|
return poll
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
if event.type == "LEFTMOUSE" and event.alt:
|
||||||
|
self.assume_unique_by_name = False
|
||||||
|
return self.execute(context)
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
self.file = IfcStore.get_file()
|
self.file = tool.Ifc.get()
|
||||||
element = ifcopenshell.api.run(
|
library_file = IfcStore.library_file
|
||||||
"project.append_asset",
|
assert library_file
|
||||||
|
element = ifcopenshell.api.project.append_asset(
|
||||||
self.file,
|
self.file,
|
||||||
library=IfcStore.library_file,
|
library=library_file,
|
||||||
element=IfcStore.library_file.by_id(self.definition),
|
element=library_file.by_id(self.definition),
|
||||||
|
assume_asset_uniqueness_by_name=self.assume_unique_by_name,
|
||||||
)
|
)
|
||||||
if not element:
|
if not element:
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
Reference in New Issue
Block a user