mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
Merge pull request #7521 from falken10vdl/fix-queries-with-backticks-in-annotations
Update formatting expression evaluation to include element context
This commit is contained in:
@@ -365,13 +365,11 @@ class DecoratorData:
|
|||||||
|
|
||||||
for literal in literals:
|
for literal in literals:
|
||||||
literal_value = literal.Literal
|
literal_value = literal.Literal
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_value = cls.evaluate_formatting_expressions(literal_value)
|
eval_value = cls.evaluate_formatting_expressions(literal_value, product)
|
||||||
current_value = tool.Drawing.replace_text_literal_variables(current_value, product)
|
current_value = tool.Drawing.replace_text_literal_variables(eval_value, product)
|
||||||
except Exception:
|
except Exception:
|
||||||
current_value = literal_value
|
current_value = literal_value
|
||||||
|
|
||||||
literal_data = {
|
literal_data = {
|
||||||
"Literal": literal_value,
|
"Literal": literal_value,
|
||||||
"BoxAlignment": literal.BoxAlignment,
|
"BoxAlignment": literal.BoxAlignment,
|
||||||
@@ -404,14 +402,14 @@ class DecoratorData:
|
|||||||
return element
|
return element
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def evaluate_formatting_expressions(cls, text: str) -> str:
|
def evaluate_formatting_expressions(cls, text: str, element=None) -> str:
|
||||||
"""Evaluate formatting expressions wrapped in backticks using ifcopenshell.util.selector.format"""
|
"""Evaluate formatting expressions wrapped in backticks using ifcopenshell.util.selector.format, always passing element context"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def evaluate_expression(match):
|
def evaluate_expression(match):
|
||||||
try:
|
try:
|
||||||
expression = match.group(1)
|
expression = match.group(1)
|
||||||
result = ifcopenshell.util.selector.format(expression)
|
result = ifcopenshell.util.selector.format(expression, element)
|
||||||
return str(result)
|
return str(result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return match.group(0)
|
return match.group(0)
|
||||||
|
|||||||
@@ -2119,17 +2119,12 @@ class Drawing(bonsai.core.tool.Drawing):
|
|||||||
|
|
||||||
for command in re.findall("``.*?``", text):
|
for command in re.findall("``.*?``", text):
|
||||||
original_command = command
|
original_command = command
|
||||||
for variable in re.findall("{{.*?}}", command):
|
|
||||||
value = ifcopenshell.util.selector.get_element_value(product, variable[2:-2])
|
|
||||||
value = '"' + str(value).replace('"', '\\"') + '"'
|
|
||||||
command = command.replace(variable, value)
|
|
||||||
# Defensive: skip if command[2:-2] is None or 'None'
|
|
||||||
command_content = command[2:-2]
|
command_content = command[2:-2]
|
||||||
if command_content is None or str(command_content).strip().lower() == "none":
|
if command_content is None or str(command_content).strip().lower() == "none":
|
||||||
text = text.replace(original_command, "")
|
text = text.replace(original_command, "")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
text = text.replace(original_command, ifcopenshell.util.selector.format(command_content))
|
text = text.replace(original_command, ifcopenshell.util.selector.format(command_content, product))
|
||||||
except Exception:
|
except Exception:
|
||||||
text = text.replace(original_command, "")
|
text = text.replace(original_command, "")
|
||||||
for variable in re.findall("{{.*?}}", text):
|
for variable in re.findall("{{.*?}}", text):
|
||||||
|
|||||||
Reference in New Issue
Block a user