mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 16:43:00 +00:00
Smart annotation variables for drawings now reimplemented. See #1153.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import re
|
||||||
import bpy
|
import bpy
|
||||||
import blenderbim.core.tool
|
import blenderbim.core.tool
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
@@ -80,5 +81,13 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def update_text_value(cls, obj):
|
def update_text_value(cls, obj):
|
||||||
element = cls.get_text_literal(obj)
|
element = cls.get_text_literal(obj)
|
||||||
if element:
|
if not element:
|
||||||
obj.BIMTextProperties.value = element.Literal
|
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
|
||||||
|
|||||||
@@ -138,8 +138,38 @@ class TestImportTextProduct(NewFile):
|
|||||||
|
|
||||||
|
|
||||||
class TestUpdateTextValue(NewFile):
|
class TestUpdateTextValue(NewFile):
|
||||||
def test_run(self):
|
def test_updating_arbitrary_strings(self):
|
||||||
TestGetTextLiteral().test_run()
|
TestGetTextLiteral().test_run()
|
||||||
obj = bpy.data.objects.get("Object")
|
obj = bpy.data.objects.get("Object")
|
||||||
subject.update_text_value(obj)
|
subject.update_text_value(obj)
|
||||||
assert obj.BIMTextProperties.value == "Literal"
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user