mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
You can now browse to select files for any URI reference attributes
This commit is contained in:
@@ -48,6 +48,9 @@ def draw_attribute(attribute, layout, copy_operator=None):
|
||||
if copy_operator:
|
||||
op = layout.operator(f"{copy_operator}", text="", icon="COPYDOWN")
|
||||
op.name = attribute.name
|
||||
if attribute.is_uri:
|
||||
op = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER")
|
||||
op.data_path = attribute.path_from_id("string_value")
|
||||
|
||||
|
||||
def import_attributes(ifc_class, props, data, callback=None):
|
||||
@@ -78,6 +81,8 @@ def import_attribute(attribute, props, data, callback=None):
|
||||
props.remove(len(props) - 1)
|
||||
elif data_type == "string":
|
||||
new.string_value = "" if new.is_null else data[attribute.name()]
|
||||
if attribute.type_of_attribute().declared_type().name() == "IfcURIReference":
|
||||
new.is_uri = True
|
||||
elif data_type == "boolean":
|
||||
new.bool_value = False if new.is_null else data[attribute.name()]
|
||||
elif data_type == "integer":
|
||||
|
||||
@@ -39,6 +39,39 @@ class OpenUri(bpy.types.Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class SelectURIAttribute(bpy.types.Operator):
|
||||
bl_idname = "bim.select_uri_attribute"
|
||||
bl_label = "Select URI Attribute"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_description = "Select a local file"
|
||||
data_path: bpy.props.StringProperty(name="Data Path")
|
||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||
|
||||
def execute(self, context):
|
||||
# data_path contains the latter half of the path to the string_value property
|
||||
# I have no idea how to find out the former half, so let's just use brute force.
|
||||
data_path = self.data_path.replace(".string_value", "")
|
||||
attribute = None
|
||||
try:
|
||||
attribute = eval(f"bpy.context.scene.{data_path}")
|
||||
except:
|
||||
try:
|
||||
attribute = eval(f"bpy.context.active_object.{data_path}")
|
||||
except:
|
||||
try:
|
||||
attribute = eval(f"bpy.context.active_object.active_material.{data_path}")
|
||||
except:
|
||||
# Do you know a better way?
|
||||
pass
|
||||
if attribute:
|
||||
attribute.string_value = self.filepath
|
||||
return {"FINISHED"}
|
||||
|
||||
def invoke(self, context, event):
|
||||
context.window_manager.fileselect_add(self)
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
|
||||
class SelectIfcFile(bpy.types.Operator, IFCFileSelector):
|
||||
bl_idname = "bim.select_ifc_file"
|
||||
bl_label = "Select IFC File"
|
||||
|
||||
@@ -190,10 +190,11 @@ class Attribute(PropertyGroup):
|
||||
bool_value: BoolProperty(name="Value", update=updateAttributeValue)
|
||||
int_value: IntProperty(name="Value", update=updateAttributeValue)
|
||||
float_value: FloatProperty(name="Value", update=updateAttributeValue)
|
||||
is_null: BoolProperty(name="Is Null")
|
||||
is_optional: BoolProperty(name="Is Optional")
|
||||
enum_items: StringProperty(name="Value")
|
||||
enum_value: EnumProperty(items=getAttributeEnumValues, name="Value", update=updateAttributeValue)
|
||||
is_null: BoolProperty(name="Is Null")
|
||||
is_optional: BoolProperty(name="Is Optional")
|
||||
is_uri: BoolProperty(name="Is Uri", default=False)
|
||||
|
||||
def get_value(self):
|
||||
if self.is_null:
|
||||
|
||||
Reference in New Issue
Block a user