Skip to content

Commit db224ac

Browse files
committed
add more func
1 parent 73ce390 commit db224ac

File tree

2 files changed

+120
-7
lines changed

2 files changed

+120
-7
lines changed

src/revit_meows.py

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(self, urn: str, token: Token, region: str = "US") -> None:
3737
self.urn = urn
3838
self.token = token
3939
self.region = region
40+
self.manifest = None # json manifest
41+
self.aec_model_info = None # json aec model info
4042

4143
@staticmethod
4244
def _urn_to_item_version(urn):
@@ -112,7 +114,6 @@ def _recursive_category(self, child, category, cat_id, df) -> pd.DataFrame:
112114
df = self._recursive_category(item, category, cat_id, df)
113115
return df
114116

115-
116117
def get_object_tree_category(self, model_guid=None) -> pd.DataFrame:
117118
"""
118119
Get the object tree category of the model
@@ -366,12 +367,12 @@ def get_bounding_boxs(self, project_id) -> pd.DataFrame:
366367
"versionUrn": item_version
367368
}]
368369
}
369-
response = requests.post(url, headers=headers, json=data,timeout=10)
370+
response = requests.post(url, headers=headers, json=data, timeout=10)
370371
if response.status_code != 200:
371372
raise requests.exceptions.HTTPError(f"Failed to get bounding box: {response.text}", response.status_code)
372373
version_index_result = response.json()
373374
while version_index_result["indexes"][0]["state"] != "FINISHED":
374-
response = requests.post(url, headers=headers, json=data,timeout=10)
375+
response = requests.post(url, headers=headers, json=data, timeout=10)
375376
version_index_result = response.json()
376377
time.sleep(2)
377378
index_id = response.json()["indexes"][0]["indexId"]
@@ -421,3 +422,115 @@ def get_all_data_bbox(self, project_id, model_guid=None, is_field_param=False,
421422
df_bbox = df_bbox.drop(columns=['object_id'])
422423
df_merge = pd.merge(df, df_bbox, on="externalId")
423424
return df_merge
425+
426+
def get_manifest(self):
427+
url = f"{self.host}/{self.urn}/manifest"
428+
headers = {
429+
"Authorization": f"Bearer {self.token.access_token}"
430+
}
431+
response = requests.get(url, headers=headers)
432+
if response.status_code != 200:
433+
raise requests.exceptions.HTTPError(f"Failed to get manifest: {response.text}", response.status_code)
434+
return response.json()
435+
436+
def get_aec_model_info(self):
437+
if self.manifest is None:
438+
self.manifest = self.get_manifest()
439+
childs = self.manifest["derivatives"][0]["children"]
440+
aec_urn = [child["urn"] for child in childs if child["role"] == "Autodesk.AEC.ModelData"][0]
441+
if aec_urn is None:
442+
raise ValueError("can't find aec model urn")
443+
url = f"{self.host}/{self.urn}/manifest/{aec_urn}"
444+
headers = {
445+
"Authorization": f"Bearer {self.token.access_token}"
446+
}
447+
response_aec_model = requests.get(url, headers=headers)
448+
if response_aec_model.status_code != 200:
449+
raise requests.exceptions.HTTPError(f"Failed to get aec model info: {response_aec_model.text}",
450+
response_aec_model.status_code)
451+
return response_aec_model.json()
452+
453+
def get_derivatives(self) -> pd.DataFrame:
454+
if self.manifest is None:
455+
self.manifest = self.get_manifest()
456+
derivatives = self.manifest["derivatives"]
457+
derivatives_df = pd.json_normalize(derivatives)
458+
return derivatives_df
459+
460+
def get_document_id(self) -> str:
461+
if self.aec_model_info is None:
462+
self.aec_model_info = self.get_aec_model_info()
463+
464+
if "documentId" not in self.aec_model_info:
465+
raise ValueError("can't find documentId")
466+
return self.aec_model_info["documentId"]
467+
468+
def get_phases(self) -> pd.DataFrame:
469+
if self.aec_model_info is None:
470+
self.aec_model_info = self.get_aec_model_info()
471+
if "phases" not in self.aec_model_info:
472+
raise ValueError("can't find phases")
473+
phases = self.aec_model_info["phases"]
474+
phases_df = pd.DataFrame(phases)
475+
return phases_df
476+
477+
def get_levels(self) -> pd.DataFrame:
478+
if self.aec_model_info is None:
479+
self.aec_model_info = self.get_aec_model_info()
480+
if "levels" not in self.aec_model_info:
481+
raise ValueError("can't find levels")
482+
levels = self.aec_model_info["levels"]
483+
levels_df = pd.json_normalize(levels)
484+
levels_df["elevation"] = levels_df["elevation"].astype(float)
485+
levels_df["height"] = levels_df["height"].astype(float)
486+
return levels_df
487+
488+
def get_scopeBoxes(self) -> pd.DataFrame:
489+
if self.aec_model_info is None:
490+
self.aec_model_info = self.get_aec_model_info()
491+
if "scopeBoxes" not in self.aec_model_info:
492+
raise ValueError("can't find scopeBoxes")
493+
scope_boxes = self.aec_model_info["scopeBoxes"]
494+
scope_boxes_df = pd.json_normalize(scope_boxes)
495+
return scope_boxes_df
496+
497+
def get_ref_point_transformation(self) -> pd.DataFrame:
498+
if self.aec_model_info is None:
499+
self.aec_model_info = self.get_aec_model_info()
500+
if "refPointTransformation" not in self.aec_model_info:
501+
raise ValueError("can't find refPointTransformation")
502+
refPointTransformation = self.aec_model_info["refPointTransformation"]
503+
new_df = pd.DataFrame()
504+
for i in range(4):
505+
new_df[f"col{i + 1}"] = refPointTransformation[i * 3:i * 3 + 3]
506+
new_df.reindex()
507+
# rename columns x,y,z,t
508+
new_df.columns = ["x", "y", "z", "t"]
509+
return new_df
510+
511+
def get_grids(self) -> pd.DataFrame:
512+
if self.aec_model_info is None:
513+
self.aec_model_info = self.get_aec_model_info()
514+
if "grids" not in self.aec_model_info:
515+
raise ValueError("can't find grids")
516+
grids = self.aec_model_info["grids"]
517+
grids_df = pd.json_normalize(grids)
518+
return grids_df
519+
520+
def get_linked_documents(self) -> pd.DataFrame:
521+
if self.aec_model_info is None:
522+
self.aec_model_info = self.get_aec_model_info()
523+
if "linkedDocuments" not in self.aec_model_info:
524+
raise ValueError("can't find linkedDocuments")
525+
linked_documents = self.aec_model_info["linkedDocuments"]
526+
linked_documents_df = pd.json_normalize(linked_documents)
527+
return linked_documents_df
528+
529+
def get_location_parameters(self) -> pd.DataFrame:
530+
if self.aec_model_info is None:
531+
self.aec_model_info = self.get_aec_model_info()
532+
if "locationParameters" not in self.aec_model_info:
533+
raise ValueError("can't find locationParameters")
534+
location_parameters = self.aec_model_info["locationParameters"]
535+
location_parameters_df = pd.json_normalize(location_parameters)
536+
return location_parameters_df

test/test_revit_acc_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from unittest import TestCase
22
from aps_toolkit import Auth
3-
from .context import APSRevit
3+
from revit_meows import APSRevit
44
import os
55
import json
66

@@ -14,15 +14,15 @@ def setUp(self):
1414
full_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..','test', file_name))
1515
if not os.path.exists(full_path):
1616
# create
17-
with open(full_path, 'w') as json_file:
17+
with open(full_path, 'w', encoding='utf-8') as json_file:
1818
data = {"refresh_token":""}
1919
json.dump(data,json_file,indent=2)
20-
with open(full_path) as json_file:
20+
with open(full_path, encoding='utf-8') as json_file:
2121
data = json.load(json_file)
2222
self.refresh_token = data['refresh_token']
2323
self.token = Auth.refresh_token_from_env(self.refresh_token)
2424
# save to json refresh token
25-
with open(full_path, 'w') as json_file:
25+
with open(full_path, 'w', encoding='utf-8') as json_file:
2626
data['refresh_token'] = self.token.refresh_token
2727
json.dump(data,json_file,indent=2)
2828
self.aps_revit = APSRevit(self.urn, self.token)

0 commit comments

Comments
 (0)