Smart annotation variables for drawings now reimplemented. See #1153.

This commit is contained in:
Dion Moult
2022-01-22 21:00:04 +11:00
parent 7e7c54a535
commit 0bdb4b9fcf
2 changed files with 42 additions and 3 deletions
+11 -2
View File
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import re
import bpy
import blenderbim.core.tool
import blenderbim.tool as tool
@@ -80,5 +81,13 @@ class Drawing(blenderbim.core.tool.Drawing):
@classmethod
def update_text_value(cls, obj):
element = cls.get_text_literal(obj)
if element:
obj.BIMTextProperties.value = element.Literal
if not element:
return
value = element.Literal
product = cls.get_text_product(tool.Ifc.get_entity(obj))
if product:
selector = ifcopenshell.util.selector.Selector()
variables = {}
for variable in re.findall("{{.*?}}", value):
value = value.replace(variable, selector.get_element_value(product, variable[2:-2]) or "")
obj.BIMTextProperties.value = value
+31 -1
View File
@@ -138,8 +138,38 @@ class TestImportTextProduct(NewFile):
class TestUpdateTextValue(NewFile):
def test_run(self):
def test_updating_arbitrary_strings(self):
TestGetTextLiteral().test_run()
obj = bpy.data.objects.get("Object")
subject.update_text_value(obj)
assert obj.BIMTextProperties.value == "Literal"
def test_using_attribute_variables(self):
TestGetTextLiteral().test_run()
obj = bpy.data.objects.get("Object")
ifc = tool.Ifc.get()
wall = ifc.createIfcWall(Name="Baz")
label = ifc.by_type("IfcAnnotation")[0]
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifc.by_type("IfcTextLiteralWithExtent")[0].Literal = "Foo {{Name}} Bar"
subject.update_text_value(obj)
assert obj.BIMTextProperties.value == "Foo Baz Bar"
def test_using_property_variables(self):
TestGetTextLiteral().test_run()
obj = bpy.data.objects.get("Object")
ifc = tool.Ifc.get()
wall = ifc.createIfcWall()
pset = ifcopenshell.api.run("pset.add_pset", ifc, name="Custom_Pset", product=wall)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Key": "Baz"})
label = ifc.by_type("IfcAnnotation")[0]
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifc.by_type("IfcTextLiteralWithExtent")[0].Literal = "Foo {{Custom_Pset.Key}} Bar"
subject.update_text_value(obj)
assert obj.BIMTextProperties.value == "Foo Baz Bar"