Skip to content

Commit

Permalink
feat(extra): Add component to open files in associated program
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Sep 12, 2020
1 parent 564c153 commit a5dfca9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ladybug_grasshopper/src/LB Open Directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

ghenv.Component.Name = 'LB Open Directory'
ghenv.Component.NickName = 'OpenDir'
ghenv.Component.Message = '0.1.0'
ghenv.Component.Message = '0.1.1'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '4 :: Extra'
ghenv.Component.AdditionalHelpFromDocStrings = '0'
ghenv.Component.AdditionalHelpFromDocStrings = '5'

import os
import subprocess
Expand Down
43 changes: 43 additions & 0 deletions ladybug_grasshopper/src/LB Open File.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Ladybug: A Plugin for Environmental Analysis (GPL)
# This file is part of Ladybug.
#
# Copyright (c) 2020, Ladybug Tools.
# You should have received a copy of the GNU General Public License
# along with Ladybug; If not, see <http://www.gnu.org/licenses/>.
#
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>

"""
Open a file in whatever program is associated with the file extension.
This can be used to open simulation files in particular applications (eg. opening
an OSM file in the OpenStudio Application).
-
Args:
_file_path: Full path to a file to be opened.
Returns:
report: Reports, errors, warnings, etc.
"""

ghenv.Component.Name = 'LB Open File'
ghenv.Component.NickName = 'OpenFile'
ghenv.Component.Message = '0.1.0'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '4 :: Extra'
ghenv.Component.AdditionalHelpFromDocStrings = '5'

import os
import subprocess

try:
from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
# check that the file exists
assert os.path.exists(_file_path), \
'No file was found at: {}'.format(_file_path)
os.startfile(_file_path)
Binary file modified ladybug_grasshopper/user_objects/LB Open Directory.ghuser
Binary file not shown.
Binary file not shown.

0 comments on commit a5dfca9

Please sign in to comment.