Hi All
I’m wrapping up the first version of my app and aiming to include a feature to enhance its appeal. I want users to be able to export geometry to Revit as native objects via a JSON file. I’m stuck transferring data from the datagroup in the convert_dynamo_file_to_data_items
method to the content_json
method. Could you take a look and help out?
Thank you.
Class Controller(ViktorController):
# Extract the output values from the output file for display on Viktor.
@staticmethod
def convert_dynamo_file_to_data_items(input_file: DynamoFile, output_file: File) -> DataGroup:
"""Extracts the output of the Dynamo results by using the input and output files."""
# Collect ids for the computational output from the dynamo file (numerical output)
output_site_area_id = input_file.get_node_id("Parking Lot Area")
output_parking_count_id = input_file.get_node_id("Parking Count")
output_green_area_id = input_file.get_node_id("Green Surface Area")
output_green_percent_id = input_file.get_node_id("Green Area %")
# Collect the numerical results from the output file using the collected ids
with output_file.open_binary() as f:
site_area = get_dynamo_result(f, id_=output_site_area_id)
parking_count = get_dynamo_result(f, id_=output_parking_count_id)
green_area = get_dynamo_result(f, id_=output_green_area_id)
green_percent = get_dynamo_result(f, id_=output_green_percent_id)
# Add values to a structured data group
data_group = DataGroup(
DataItem(label="Site Area", value=site_area, suffix="m²"),
DataItem(label="Parking Count", value=parking_count, suffix="spots"),
DataItem(label="Green Area", value=green_area, suffix="m²"),
DataItem(label="Green Area Percentage", value=green_percent, suffix="%"),
)
# Return the data group for display of outputs in the Viktor app.
return data_group
# Define the contents of the JSON file to be downloaded.
def content_json(self):
"""Define function to create JSON file contents for user download."""
# Define the content to be placed in the download JSON file.
content = "how do I get a value from the convert_dynamo_file_to_data_items function in here?"
# Return the content.
return content
# Define function to download the JSON file to create the designed elements in the user's software.
def download_json(self):
"""Define function to download the JSON file."""
return DownloadResult(self.content_json(), 'create_elements.json')