Skip to content

Commit

Permalink
fix(serialize): Add an option for extension to V=validation component
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Dec 5, 2024
1 parent 62825a2 commit f5f8198
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Binary file modified honeybee_grasshopper_core/icon/HB Validate Model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions honeybee_grasshopper_core/json/HB_Validate_Model.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "ValidateModel",
"outputs": [
[]
Expand All @@ -12,6 +12,13 @@
"type": "System.Object",
"default": null
},
{
"access": "item",
"name": "x",
"description": "Optional text for the name of the honeybee extension for which\nvalidation will occur. The value input here is case-insensitive such\nthat \"radiance\" and \"Radiance\" will both result in the model being\nchecked for validity with honeybee-radiance. This value can also be\nset to \"All\" in order to run checks for all installed extensions.\nSome common honeybee extension names that can be input here if they\nare installed include:\n* Radiance\n* EnergyPlus\n* OpenStudio\n* DesignBuilder\n* DOE2\n* IES\n* IDAICE",
"type": "string",
"default": null
},
{
"access": "item",
"name": "_validate",
Expand All @@ -21,7 +28,7 @@
}
],
"subcategory": "3 :: Serialize",
"code": "\nimport os\n\ntry: # import the core honeybee dependencies\n from honeybee.config import folders\n from honeybee.model import Model\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _validate:\n # re-serialize the model if it is a HBJSON file\n if isinstance(_model, Model):\n parsed_model = _model\n elif isinstance(_model, str) and os.path.isfile(_model):\n parsed_model = Model.from_hbjson(_model)\n else:\n raise ValueError(\n 'Expected Honeybee Model object or path to a HBJSON file. '\n 'Got {}.'.format(type(_model))\n )\n\n # validate the model\n print(\n 'Validating Model using honeybee-core=={} and honeybee-schema=={}'.format(\n folders.honeybee_core_version_str, folders.honeybee_schema_version_str)\n )\n # perform several checks for geometry rules\n report = parsed_model.check_all(raise_exception=False)\n print('Model checks completed.')\n # check the report and write the summary of errors\n if report == '':\n print('Congratulations! Your Model is valid!')\n else:\n error_msg = 'Your Model is invalid for the following reasons:'\n print('\\n'.join([error_msg, report]))\n give_warning(ghenv.Component, report)\n",
"code": "\nimport os\n\ntry: # import the core honeybee dependencies\n from honeybee.config import folders\n from honeybee.model import Model\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _validate:\n # re-serialize the model if it is a HBJSON file\n if isinstance(_model, Model):\n parsed_model = _model\n elif isinstance(_model, str) and os.path.isfile(_model):\n parsed_model = Model.from_hbjson(_model)\n else:\n raise ValueError(\n 'Expected Honeybee Model object or path to a HBJSON file. '\n 'Got {}.'.format(type(_model))\n )\n\n # validate the model\n print(\n 'Validating Model using honeybee-core=={} and honeybee-schema=={}'.format(\n folders.honeybee_core_version_str, folders.honeybee_schema_version_str)\n )\n # perform several checks for geometry rules\n extension_ = 'All' if extension_ is None else extension_\n report = parsed_model.check_for_extension(extension_, raise_exception=False)\n print('Model checks completed.')\n # check the report and write the summary of errors\n if report == '':\n print('Congratulations! Your Model is valid!')\n else:\n error_msg = 'Your Model is invalid for the following reasons:'\n print('\\n'.join([error_msg, report]))\n give_warning(ghenv.Component, report)\n",
"category": "Honeybee",
"name": "HB Validate Model",
"description": "Get a validation report that contains a summary of all issues with the Model.\n_\nThis includes basic properties like adjacency checks and all geometry checks.\nFurthermore, all extension attributes for Energy and Radiance will be checked\nto ensure that the model can be simulated correctly in these engines.\n-"
Expand Down
19 changes: 17 additions & 2 deletions honeybee_grasshopper_core/src/HB Validate Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
Args:
_model: A Honeybee Model object to be validated. This can also be the file path
to a Model HBJSON that will be validated.
extension_: Optional text for the name of the honeybee extension for which
validation will occur. The value input here is case-insensitive such
that "radiance" and "Radiance" will both result in the model being
checked for validity with honeybee-radiance. This value can also be
set to "All" in order to run checks for all installed extensions.
Some common honeybee extension names that can be input here if they
are installed include:
* Radiance
* EnergyPlus
* OpenStudio
* DesignBuilder
* DOE2
* IES
* IDAICE
_validate: Set to "True" to validate the the Model and get a report of all
issues with the model.
Expand All @@ -32,7 +46,7 @@

ghenv.Component.Name = 'HB Validate Model'
ghenv.Component.NickName = 'ValidateModel'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '3 :: Serialize'
ghenv.Component.AdditionalHelpFromDocStrings = '0'
Expand Down Expand Up @@ -69,7 +83,8 @@
folders.honeybee_core_version_str, folders.honeybee_schema_version_str)
)
# perform several checks for geometry rules
report = parsed_model.check_all(raise_exception=False)
extension_ = 'All' if extension_ is None else extension_
report = parsed_model.check_for_extension(extension_, raise_exception=False)
print('Model checks completed.')
# check the report and write the summary of errors
if report == '':
Expand Down
Binary file modified honeybee_grasshopper_core/user_objects/HB Validate Model.ghuser
Binary file not shown.
Binary file modified samples/model_serialization.gh
Binary file not shown.

0 comments on commit f5f8198

Please # to comment.