예제 #1
0
def test_clean_string():
    """Test the clean_string method."""
    correct_str = '0.5 in. Gypsum Wall'
    incorrect_str = '0.5 in., Gypsum Wall'
    long_str = 'This is an exceptionally long text string that should never be used ' \
        'for the name of anything in EnergyPlus for whatever reason'

    assert clean_string(correct_str) == '0.5in.GypsumWall'
    assert clean_string(incorrect_str) == '0.5in.GypsumWall'
    with pytest.raises(AssertionError):
        clean_string(long_str)
예제 #2
0
    def add_prefix(self, prefix):
        """Change the identifier of this object by inserting a prefix.

        This is particularly useful in workflows where you duplicate and edit
        a starting object and then want to combine it with the original object
        into one Model (like making a model of repeated shades) since all objects
        within a Model must have unique identifiers.

        Args:
            prefix: Text that will be inserted at the start of this object's identifier
                and display_name. It is recommended that this prefix be short to
                avoid maxing out the 100 allowable characters for dragonfly identifiers.
        """
        self._identifier = clean_string('{}_{}'.format(prefix,
                                                       self.identifier))
        self.display_name = '{}_{}'.format(prefix, self.display_name)
        self.properties.add_prefix(prefix)
예제 #3
0
    def add_prefix(self, prefix):
        """Change the identifier and all child Room2D ids by inserting a prefix.

        This is particularly useful in workflows where you duplicate and edit
        a starting object and then want to combine it with the original object
        into one Model (like making a model of repeated stories) since all objects
        within a Model must have unique identifiers.

        This method is used internally to convert from a Story with a mutliplier
        to fully-detailed Stories with unique identifiers.

        Args:
            prefix: Text that will be inserted at the start of this object's
                (and child segments') identifier and display_name. It is recommended
                that this prefix be short to avoid maxing out the 100 allowable
                characters for dragonfly identifiers.
        """
        self._identifier = clean_string('{}_{}'.format(prefix, self.identifier))
        self.display_name = '{}_{}'.format(prefix, self.display_name)
        self.properties.add_prefix(prefix)
        for room in self.room_2ds:
            room.add_prefix(prefix)
        raise ValueError(
            'conditioned_ has been specified but dragonfly-energy '
            'has failed to import.\n{}'.format(e))

if all_required_inputs(ghenv.Component) and _run:
    perim_offset_ = 0 if perim_offset_ is None else perim_offset_
    buildings = []  # list of buildings that will be returned
    for i, geo in enumerate(_footprint_geo):
        # get the name for the Building
        if len(_name_) == 0:  # make a default Building name
            display_name = 'Building_{}'.format(document_counter('bldg_count'))
            name = clean_and_id_string(display_name)
        else:
            display_name = '{}_{}'.format(longest_list(_name_, i), i + 1) \
                if len(_name_) != len(_footprint_geo) else longest_list(_name_, i)
            name = clean_string(display_name)

        # create the Building
        building = Building.from_footprint(
            name,
            footprint=to_face3d(geo),
            floor_to_floor_heights=_floor_to_floor,
            perimeter_offset=perim_offset_,
            tolerance=tolerance)
        building.display_name = display_name

        # assign the program
        if len(_program_) != 0:
            program = longest_list(_program_, i)
            if isinstance(program, str):
                program = program_type_by_identifier(program)
try:  # import the core honeybee dependencies
    from honeybee.typing import clean_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import the core dragonfly dependencies
    from dragonfly.model import Model
except ImportError as e:
    raise ImportError('\nFailed to import dragonfly:\n\t{}'.format(e))

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

if all_required_inputs(ghenv.Component):
    # set a default name
    name = clean_string(_name_) if _name_ is not None else 'unnamed'
    units = units_system()

    # create the model
    model = Model(name,
                  _buildings,
                  context_,
                  units=units,
                  tolerance=tolerance,
                  angle_tolerance=angle_tolerance)
    if _name_ is not None:
        model.display_name = _name_