mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 13:38:05 +00:00
See #2881. Add support for evaluated commands in smart text literals
This commit is contained in:
@@ -1075,11 +1075,20 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
def replace_text_literal_variables(cls, text, product):
|
def replace_text_literal_variables(cls, text, product):
|
||||||
if not product:
|
if not product:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
for command in re.findall("``.*?``", text):
|
||||||
|
original_command = command
|
||||||
|
for variable in re.findall("{{.*?}}", command):
|
||||||
|
value = ifcopenshell.util.selector.get_element_value(product, variable[2:-2])
|
||||||
|
command = command.replace(variable, repr(value))
|
||||||
|
text = text.replace(original_command, str(eval(command[2:-2])))
|
||||||
|
|
||||||
for variable in re.findall("{{.*?}}", text):
|
for variable in re.findall("{{.*?}}", text):
|
||||||
value = ifcopenshell.util.selector.get_element_value(product, variable[2:-2])
|
value = ifcopenshell.util.selector.get_element_value(product, variable[2:-2])
|
||||||
if isinstance(value, (list, tuple)):
|
if isinstance(value, (list, tuple)):
|
||||||
value = ", ".join(str(v) for v in value)
|
value = ", ".join(str(v) for v in value)
|
||||||
text = text.replace(variable, str(value))
|
text = text.replace(variable, str(value))
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user