You can now toggle visibility and wireframe modes of linked models and fix bug where links with the same name were not unique

This commit is contained in:
Dion Moult
2022-06-09 21:47:35 +10:00
parent 97bf4e3d0d
commit 8311983d5e
4 changed files with 50 additions and 9 deletions
@@ -708,7 +708,7 @@ class LoadLink(bpy.types.Operator):
continue
bpy.data.scenes[0].collection.children.link(child)
link = context.scene.BIMProjectProperties.links.get(filepath)
link.collection_name = child.name
link.collection = child
link.is_loaded = True
return {"FINISHED"}
@@ -718,11 +718,20 @@ class ToggleLinkVisibility(bpy.types.Operator):
bl_label = "Toggle Link Visibility"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Toggle visibility between SOLID and WIREFRAME"
collection_name: bpy.props.StringProperty()
link: bpy.props.StringProperty()
mode: bpy.props.StringProperty()
def execute(self, context):
collection_name = self.collection_name
objs = filter(lambda obj: "IfcOpeningElement" not in obj.name, bpy.data.collections[collection_name].all_objects)
props = context.scene.BIMProjectProperties
link = props.links.get(self.link)
if self.mode == "WIREFRAME":
self.toggle_wireframe(link)
elif self.mode == "VISIBLE":
self.toggle_visibility(link)
return {"FINISHED"}
def toggle_wireframe(self, link):
objs = filter(lambda obj: "IfcOpeningElement" not in obj.name, link.collection.all_objects)
for i,obj in enumerate(objs):
if i == 0:
if obj.display_type == "WIRE":
@@ -730,7 +739,22 @@ class ToggleLinkVisibility(bpy.types.Operator):
else:
display_type = "WIRE"
obj.display_type = display_type
return {"FINISHED"}
link.is_wireframe = display_type == "WIRE"
def toggle_visibility(self, link):
queue = [bpy.context.view_layer.layer_collection]
layer_collection = None
while queue:
layer = queue.pop()
if layer.collection == link.collection:
layer_collection = layer
break
queue.extend(list(layer.children))
if layer_collection:
layer_collection.exclude = not layer_collection.exclude
link.is_hidden = layer_collection.exclude
class ExportIFC(bpy.types.Operator):
@@ -23,6 +23,7 @@ from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import StrProperty
from bpy.types import PropertyGroup
from bpy.props import (
PointerProperty,
BoolProperty,
CollectionProperty,
EnumProperty,
@@ -91,8 +92,10 @@ class FilterCategory(PropertyGroup):
class Link(PropertyGroup):
name: StringProperty(name="Name")
collection_name: StringProperty(name="Collection Name")
collection: PointerProperty(name="Collection", type=bpy.types.Collection)
is_loaded: BoolProperty(name="Is Loaded", default=False)
is_wireframe: BoolProperty(name="Is Wireframe", default=False)
is_hidden: BoolProperty(name="Is Hidden", default=False)
class BIMProjectProperties(PropertyGroup):
@@ -302,8 +302,22 @@ class BIM_UL_links(UIList):
row = layout.row(align=True)
if item.is_loaded:
row.label(text=item.name)
op = row.operator("bim.toggle_link_visibility", text="", icon="HIDE_OFF")
op.collection_name = item.collection_name
op = row.operator(
"bim.toggle_link_visibility",
text="",
icon="CUBE" if item.is_wireframe else "MESH_CUBE",
emboss=False,
)
op.link = item.name
op.mode = "WIREFRAME"
op = row.operator(
"bim.toggle_link_visibility",
text="",
icon="HIDE_ON" if item.is_hidden else "HIDE_OFF",
emboss=False,
)
op.link = item.name
op.mode = "VISIBLE"
op = row.operator("bim.unload_link", text="", icon="UNLINKED")
op.filepath = item.name
else:
+1 -1
View File
@@ -102,7 +102,7 @@ class Project(blenderbim.core.tool.Project):
while queue:
layer = queue.pop()
if layer.name == collection.name:
if layer.collection == collection:
layer_collection = layer
break
queue.extend(list(layer.children))