update for model collections properly support mm units

This commit is contained in:
Gergő Jedlicska
2023-07-03 19:32:39 +02:00
parent f3346fd077
commit 865ecdef01
4 changed files with 56 additions and 32 deletions
+17
View File
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"envFile": "${workspaceFolder}/.env"
}
]
}
@@ -3,6 +3,7 @@ import math
from specklepy.objects.base import Base
from specklepy.objects.other import RenderMaterial
from bg_specklepy.Geometry.sphere import Sphere
from specklepy.api.resources.commit import Commit as SpeckleCommit
from bg_specklepy.SpeckleServer.commit import Commit
from bg_specklepy.SpeckleServer.client import Client
@@ -11,6 +12,7 @@ class ColumnOffsetEvaluation():
def __init__(self,
client_obj: Client,
stream_id: str,
commit_object: SpeckleCommit,
commit_data: Base,
echo_level : int = 0,
tolerance : float = 0.01,
@@ -38,7 +40,7 @@ class ColumnOffsetEvaluation():
self.column_elements = None
self.data_frame = None
self.offset_columns_dataframe = None
self.commit_object = None
self.commit_object = commit_object
self._units = 'm'
self._units_scaling = 1
@@ -62,23 +64,26 @@ class ColumnOffsetEvaluation():
'''
# HACKY - muss einen besseren Weg geben?
if not "Revit" in self.commit_data[dir(self.commit_data)[0]][0].speckle_type:
# if not "Revit" in self.commit_object.
if "Revit" not in self.commit_object.sourceApplication:
raise NotImplementedError("Column offset evaluation currently restricted to Revit models only.")
if self.echo_level == 1:
print("[UPDATE]\t:\tRevit model detected ...")
if self.commit_data.speckle_type != "Objects.Organization.Model":
if self.commit_data.speckle_type not in ["Objects.Organization.Model", "Speckle.Core.Models.Collection"]:
raise AttributeError("Commit data not of correct speckle type. A Revit Model needs to be used as basis input.")
column_collection = [collection for collection in self.commit_data.elements if collection.applicationId == "Structural Columns"][0]
self.column_elements = column_collection.elements
# More languages to be added. But, Revit export should be standard english
for column_parameter in ["@Structural Columns", "@Tragwerksstützen"]:
try:
self.column_elements = self.commit_data[column_parameter]
self.column_parameter = column_parameter
break
except KeyError:
continue
# for column_parameter in ["@Structural Columns", "@Tragwerksstützen"]:
# try:
# self.column_elements = self.commit_data[column_parameter]
# self.column_parameter = column_parameter
# break
# except KeyError:
# continue
if self.column_elements[0].units != 'm':
if self.column_elements[0].units == 'mm':
@@ -237,7 +242,7 @@ class ColumnOffsetEvaluation():
for index, row in self.offset_columns_dataframe.iterrows():
obj = Base()
obj.units = self._units
obj["@column_above"], obj["@column_below"], obj["@offset"] = {}, {}, {}
radius = 0.35 * self._units_scaling
@@ -56,6 +56,7 @@ def main(speckle_project_data: str, function_inputs: str, speckle_token: str):
evaluation = ColumnOffsetEvaluation(
client_obj=client_obj,
stream_id=stream_id,
commit_object = commit,
commit_data = commit_data,
tolerance = inputs.tolerance,
echo_level = inputs.echo_level,
@@ -1,25 +1,26 @@
# Definierte Modell aus dem Beispiel https://speckle.xyz/streams/ff47530e95
# 3 Stützenversätze
from bg_specklepy.SpeckleServer.client import Client
from bg_specklepy.SpeckleServer.stream import Stream
from bg_specklepy.SpeckleServer.branch import Branch
from bg_specklepy.SpeckleServer.commit import Commit
from bg_specklepy.Operations.columnOffsetEvaluation import ColumnOffsetEvaluation
import os
from bg_specklepy.analysis_column_eccentricity import (
FunctionInputs,
SpeckleProjectData,
main,
)
def test_operations_column_offset_evaluation():
speckle_project_data = SpeckleProjectData(
projectId="9a9689bf01",
modelId="231110ac11-institute-var-2-ifc.ifc",
versionId="c13d21b3cf",
speckleServerUrl="http://latest.speckle.systems",
)
function_inputs = FunctionInputs(tolerance=0.02, echoLevel=1, scaleSpheres=False)
speckle_token = os.getenv("SPECKLE_TOKEN")
main(
speckle_project_data.json(by_alias=True),
function_inputs.json(by_alias=True),
speckle_token,
)
speckle_server = "insert"
speckle_token = "insert"
client_obj = Client(speckle_server, speckle_token)
stream_obj = Stream(client_obj, 0)
branch_obj = Branch(client_obj, stream_obj, 6)
commit_data = Commit.get_data(branch_obj, 0)
evaluation = ColumnOffsetEvaluation(commit_data = commit_data,
tolerance = 0.02,
echo_level = 0,
scale_spheres = False)
evaluation.run()
assert len(evaluation.commit_data["@Analysis_ColumnEccentricity"]) == 3
if __name__ == ("__main__"):
test_operations_column_offset_evaluation()