New feature to bulk add smart annotations to objects

This commit is contained in:
Dion Moult
2020-05-07 09:36:38 +10:00
parent 0af8902dde
commit 673f12dd8a
6 changed files with 64 additions and 20 deletions
@@ -124,6 +124,7 @@ if bpy is not None:
operator.ResizeText,
operator.AddVariable,
operator.RemoveVariable,
operator.PropagateTextData,
prop.StrProperty,
prop.Variable,
prop.Classification,
@@ -16,13 +16,17 @@ class Annotator:
return float(sizes[str(size)])
@staticmethod
def add_text():
def add_text(related_element=None):
curve = bpy.data.curves.new(type='FONT', name='Text')
curve.body = 'TEXT'
obj = bpy.data.objects.new('Text', curve)
obj.matrix_world = bpy.context.scene.camera.matrix_world
co1, co2 = Annotator.get_placeholder_coords()
obj.location = co1
if related_element is None:
location, co2 = Annotator.get_placeholder_coords()
else:
obj.data.BIMTextProperties.related_element = related_element
location = related_element.location
obj.location = location
obj.hide_render = True
font = bpy.data.fonts.get('OpenGost TypeB TT')
if not font:
+22 -12
View File
@@ -214,18 +214,7 @@ class IfcCutter:
data = {}
for text_obj in self.text_objs:
text_obj_data = {}
text_body = text_obj.data.body
for variable in text_obj.data.BIMTextProperties.variables:
element = self.get_ifc_element(variable.global_id)
if element:
if '{{' in variable.prop_key:
prop_key = variable.prop_key.split('{{')[1].split('}}')[0]
prop_value = self.ifc_attribute_extractor.get_element_key(element, prop_key)
variable_value = eval(variable.prop_key.replace('{{' + prop_key + '}}', str(prop_value)))
else:
variable_value = self.ifc_attribute_extractor.get_element_key(element, variable.prop_key)
text_obj_data[variable.name] = variable_value
text_obj_data = self.get_text_variables(text_obj)
if text_obj_data:
data[text_obj.name] = text_obj_data
@@ -234,6 +223,27 @@ class IfcCutter:
self.template_variables = data
def get_text_variables(self, text_obj):
text_obj_data = {}
text_body = text_obj.data.body
related_element = text_obj.data.BIMTextProperties.related_element
if not related_element:
return
global_id = related_element.BIMObjectProperties.attributes.get('GlobalId')
if not global_id:
return
element = self.get_ifc_element(global_id.string_value)
for variable in text_obj.data.BIMTextProperties.variables:
if element:
if '{{' in variable.prop_key:
prop_key = variable.prop_key.split('{{')[1].split('}}')[0]
prop_value = self.ifc_attribute_extractor.get_element_key(element, prop_key)
variable_value = eval(variable.prop_key.replace('{{' + prop_key + '}}', str(prop_value)))
else:
variable_value = self.ifc_attribute_extractor.get_element_key(element, variable.prop_key)
text_obj_data[variable.name] = variable_value
return text_obj_data
def get_product_shapes(self):
if not self.should_recut:
return
@@ -2405,7 +2405,11 @@ class AddAnnotation(bpy.types.Operator):
if not bpy.context.scene.camera:
return {'FINISHED'}
if self.data_type == 'text':
obj = annotation.Annotator.add_text()
if bpy.context.selected_objects:
for selected_object in bpy.context.selected_objects:
obj = annotation.Annotator.add_text(related_element=selected_object)
else:
obj = annotation.Annotator.add_text()
else:
obj = annotation.Annotator.get_annotation_obj(self.obj_name, self.data_type)
obj = annotation.Annotator.add_line_to_annotation(obj)
@@ -2443,3 +2447,26 @@ class RemoveVariable(bpy.types.Operator):
def execute(self, context):
bpy.context.active_object.data.BIMTextProperties.variables.remove(self.index)
return {'FINISHED'}
class PropagateTextData(bpy.types.Operator):
bl_idname = 'bim.propagate_text_data'
bl_label = 'Propagate Text Data'
def execute(self, context):
source = bpy.context.active_object
for obj in bpy.context.selected_objects:
if obj == source:
continue
obj.data.body = source.data.body
obj.data.align_x = source.data.align_x
obj.data.align_y = source.data.align_y
obj.data.BIMTextProperties.font_size = source.data.BIMTextProperties.font_size
obj.data.BIMTextProperties.symbol = source.data.BIMTextProperties.symbol
while len(obj.data.BIMTextProperties.variables) > 0:
obj.data.BIMTextProperties.variables.remove(0)
for variable in source.data.BIMTextProperties.variables:
new_variable = obj.data.BIMTextProperties.variables.add()
new_variable.name = variable.name
new_variable.prop_key = variable.prop_key
return {'FINISHED'}
+1 -1
View File
@@ -377,7 +377,6 @@ class StrProperty(PropertyGroup):
class Variable(PropertyGroup):
name: StringProperty(name="Name")
global_id: StringProperty(name="Global ID")
prop_key: StringProperty(name="Property Key")
@@ -415,6 +414,7 @@ class BIMTextProperties(PropertyGroup):
('None', 'None', ''),
('rectangle-tag', 'Rectangle Tag', ''),
], update=refreshFontSize, name='Symbol')
related_element: PointerProperty(name='Related Element', type=bpy.types.Object)
variables: CollectionProperty(name='Variables', type=Variable)
+5 -3
View File
@@ -658,10 +658,14 @@ class BIM_PT_text(Panel):
props = context.active_object.data.BIMTextProperties
row = layout.row()
row.prop(props, 'font_size')
row.operator('bim.propagate_text_data')
row = layout.row()
row.prop(props, 'font_size')
row = layout.row()
row.prop(props, 'symbol')
row = layout.row()
row.prop(props, 'related_element')
row = layout.row()
row.operator('bim.add_variable')
@@ -671,8 +675,6 @@ class BIM_PT_text(Panel):
row.prop(variable, 'name')
row.operator('bim.remove_variable', icon='X', text='').index = index
row = layout.row()
row.prop(variable, 'global_id')
row = layout.row()
row.prop(variable, 'prop_key')