Updating sheet name from UI #2950

This commit is contained in:
Andrej730
2023-04-07 19:02:40 +05:00
parent 788f1154da
commit cc34e16c6b
4 changed files with 39 additions and 22 deletions
@@ -856,6 +856,10 @@ class ChangeSheetTitleBlock(bpy.types.Operator):
def execute(self, context):
scene = context.scene
props = scene.DocProperties
if not len(props.sheets):
return {"CANCELLED"}
active_sheet = props.sheets[props.active_sheet_index]
sheet = tool.Ifc.get().by_id(active_sheet.ifc_definition_id)
@@ -250,11 +250,18 @@ class Schedule(PropertyGroup):
class Sheet(PropertyGroup):
def set_name(self, new):
old = self.get("name")
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "sheets")
if old and os.path.isfile(os.path.join(path, old + ".svg")):
os.rename(os.path.join(path, old + ".svg"), os.path.join(path, new + ".svg"))
if new == old:
return
sheet = tool.Ifc.get().by_id(self.ifc_definition_id)
old_path = Path(tool.Drawing.get_document_uri(sheet))
core.update_sheet_name(tool.Ifc, tool.Drawing, sheet=sheet, name=new)
self["name"] = new
new_path = Path(tool.Drawing.get_document_uri(sheet))
if old and old_path.is_file():
old_path.rename(new_path)
def get_name(self):
return self.get("name")
@@ -506,26 +506,27 @@ class BIM_UL_drawinglist(bpy.types.UIList):
class BIM_UL_sheets(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if item:
row = layout.row(align=True)
if not item:
layout.label(text="", translate=False)
return
if item.is_sheet:
if item.is_expanded:
row.operator(
"bim.contract_sheet", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN"
).sheet = item.ifc_definition_id
else:
row.operator(
"bim.expand_sheet", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT"
).sheet = item.ifc_definition_id
row = layout.row()
if item.is_sheet:
if item.is_expanded:
row.operator(
"bim.contract_sheet", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN"
).sheet = item.ifc_definition_id
else:
row.label(text="", icon="BLANK1")
if item.reference_type == "DRAWING":
row.label(text="", icon="IMAGE_DATA")
elif item.reference_type == "SCHEDULE":
row.label(text="", icon="LONGDISPLAY")
row.operator(
"bim.expand_sheet", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT"
).sheet = item.ifc_definition_id
name = "{} - {}".format(item.identification or "X", item.name or "Unnamed")
row.prop(item, "name", text=item.identification or "X", emboss=False)
else:
row.label(text="", icon="BLANK1")
if item.reference_type == "DRAWING":
row.label(text="", icon="IMAGE_DATA")
elif item.reference_type == "SCHEDULE":
row.label(text="", icon="LONGDISPLAY")
name = "{} - {}".format(item.identification or "X", item.name or "Unnamed")
row.label(text=name)
else:
layout.label(text="", translate=False)
@@ -86,6 +86,11 @@ def remove_sheet(ifc, drawing, sheet=None):
drawing.import_sheets()
def update_sheet_name(ifc, drawing, sheet=None, name=None):
if drawing.get_name(sheet) != name:
ifc.run("document.edit_information", information=sheet, attributes={"Name": name})
def load_schedules(drawing):
drawing.import_schedules()
drawing.enable_editing_schedules()