2 Commits

Author SHA1 Message Date
Jonathon Broughton e2bfdefc6d additional MEP elements
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-02-09 12:32:25 +00:00
Jonathon Broughton ce0299bccf De-optimise from bounding box clashes 2024-02-09 12:31:50 +00:00
2 changed files with 32 additions and 19 deletions
+8 -3
View File
@@ -88,8 +88,13 @@ def speckle_mesh_to_trimesh(input_mesh: SpeckleMesh) -> trimesh.Trimesh:
t_mesh = trimesh.Trimesh(vertices=vertices, faces=np.array(faces))
obbox = t_mesh.bounding_box_oriented
return t_mesh
obbox_mesh = obbox.to_mesh()
# code below speeds up the process but is not used in the current implementation.
# Bounding boxes could be used for a 2-pass approach to speed up the process.
return obbox_mesh
# obbox = t_mesh.bounding_box_oriented
# obbox_mesh = obbox.to_mesh()
# return obbox_mesh
+24 -16
View File
@@ -2,6 +2,7 @@
use the automation_context module to wrap your function in an Automate context helper
"""
from collections import defaultdict
from typing import Optional
@@ -44,19 +45,22 @@ class FunctionInputs(AutomateBase):
Negative values relaxes the test, positive values make it more strict.",
json_schema_extra={
"readOnly": True,
}
},
)
tolerance_unit: str = Field( # Using the SpecklePy Units enum here
default=Units.mm,
json_schema_extra={"examples": ["mm", "cm", "m"], "readOnly": True},
title="Tolerance Unit",
description="Unit of the tolerance value.",
json_schema_extra={
"examples": ["mm", "cm", "m"],
"readOnly": True
},
)
def automate_function(
automate_context: AutomationContext,
function_inputs: FunctionInputs,
automate_context: AutomationContext,
function_inputs: FunctionInputs,
) -> None:
"""This is an example Speckle Automate function.
@@ -71,10 +75,12 @@ def automate_function(
changed_model_version = automate_context.receive_version()
try:
reference_model_version, reference_model_id, reference_model_version_id = get_reference_model(
automate_context, function_inputs.static_model_name
reference_model_version, reference_model_id, reference_model_version_id = (
get_reference_model(automate_context, function_inputs.static_model_name)
)
print(
f"Reference model id: {reference_model_id}, version id: {reference_model_version_id}"
)
print(f"Reference model id: {reference_model_id}, version id: {reference_model_version_id}")
except Exception as ex:
automate_context.mark_run_failed(status_message=str(ex))
@@ -100,6 +106,8 @@ def automate_function(
"Objects.BuiltElements.Duct",
"Objects.BuiltElements.Duct:Objects.BuiltElements.Revit.RevitDuct",
"Objects.BuiltElements.Duct:Objects.BuiltElements.Revit.RevitDuct:Objects.BuiltElements.Revit.RevitFlexDuct",
"Objects.Other.Revit.RevitInstance:Objects.BuiltElements.Revit.RevitMEPFamilyInstance",
"Objects.BuiltElements.Revit.RevitElementType:Objects.BuiltElements.Revit.RevitSymbolElementType"
]
visible_beams_rule = element_rules.rule_combiner(
@@ -138,20 +146,20 @@ def automate_function(
status_message="Clash detection failed. No objects to compare."
)
return
clashes = detect_and_report_clashes(
reference_mesh_elements, latest_mesh_elements, tolerance, automate_context
)
percentage_reference_objects_clashing = (
len(set([ref_id for ref_id, latest_id in clashes]))
/ len(reference_mesh_elements)
* 100
len(set([ref_id for ref_id, latest_id in clashes]))
/ len(reference_mesh_elements)
* 100
)
percentage_latest_objects_clashing = (
len(set([latest_id for ref_id, latest_id in clashes]))
/ len(latest_mesh_elements)
* 100
len(set([latest_id for ref_id, latest_id in clashes]))
/ len(latest_mesh_elements)
* 100
)
# all clashes count
@@ -177,7 +185,7 @@ def automate_function(
def get_reference_model(
automate_context: AutomationContext, static_model_name: str
automate_context: AutomationContext, static_model_name: str
) -> tuple[Base, Optional[str], Optional[str]]:
# the static reference model will be retrieved from the project using model name stored in the inputs
speckle_client = automate_context.speckle_client