示例#1
0
def resolve_naming_conflicts(category, sched_name, fields, doc=None):
    """Decide what to do if there is an existing sched with identical name

    This function needs to check these conditions, in this order:
        1- exisiting key schedule for given category, with any of the fields
        2- existing any schedule with matching name

    Exisiting key schedule for given category, with identical fields, has
    already been checked for and the update function would be called
    """
    doc = doc or revit.doc

    all_schedules = \
        revit.query.get_all_views(doc=doc, view_types=[DB.ViewType.Schedule])
    # check for existing key schedules (check 1)
    matching_keysched = next(
        (x for x in all_schedules if x.Definition.IsKeySchedule
         and x.Definition.CategoryId == category.Id), None)
    if matching_keysched:
        cfield = has_field_conflicts(matching_keysched.Definition, fields)
        if cfield:
            if forms.alert(
                    "Field \"{}\" is already used by another "
                    "key schedule \"{}\". Multiple key schedules can not "
                    "set values for same parameter. Do you want to delete "
                    "the existing key schedule first?".format(
                        cfield, matching_keysched.Name),
                    yes=True,
                    no=True):
                # the the process continue to check matching names below
                if not safe_delete_keysched(doc, matching_keysched):
                    return None
            else:
                return None

    # by now, if there was a key schdule matching name, it is deleted
    # check for matching view names, of other types
    all_schedules = \
        revit.query.get_all_views(doc=doc, view_types=[DB.ViewType.Schedule])
    existing_sched = \
        revit.query.get_view_by_name(sched_name,
                                     view_types=[DB.ViewType.Schedule])
    if existing_sched:
        if forms.alert(
                "There is an existing schedule with the same name \"{}\"."
                "Do you want to choose a new name for this key schedule?".
                format(sched_name),
                yes=True,
                no=True):
            return forms.ask_for_unique_string(
                reserved_values=[x.Name for x in all_schedules],
                default='{} {}'.format(sched_name, coreutils.current_date()))
        return None
    return sched_name
示例#2
0
    def pick_key(self, sender, args):
        # remove previously reserved
        if self._reserved_key:
            try:
                kdb.release_key(self._conn,
                                self._reserved_key,
                                category=self._cat)
            except System.TimeoutException as toutex:
                forms.alert(toutex.Message)
                return

        try:
            categories = kdb.get_categories(self._conn)
            keynotes = kdb.get_keynotes(self._conn)
            locks = kdb.get_locks(self._conn)
        except System.TimeoutException as toutex:
            forms.alert(toutex.Message)
            return

        # collect existing keys
        reserved_keys = [x.key for x in categories]
        reserved_keys.extend([x.key for x in keynotes])
        reserved_keys.extend([x.LockTargetRecordKey for x in locks])
        # ask for a unique new key
        new_key = forms.ask_for_unique_string(
            prompt='Enter a Unique Key',
            title=self.Title,
            reserved_values=reserved_keys,
            owner=self)
        if new_key:
            try:
                kdb.reserve_key(self._conn, new_key, category=self._cat)
            except System.TimeoutException as toutex:
                forms.alert(toutex.Message)
                return
            self._reserved_key = new_key
            # set the key value on the button
            self.active_key = new_key
示例#3
0
def resolve_messy_conflicts(category, sched_name, fields, doc=None):
    """Decide what to do if there is an existing sched with identical name"""
    doc = doc or revit.doc
    all_schedules = \
        revit.query.get_all_views(doc=doc, view_types=[DB.ViewType.Schedule])
    # check for existing key schedules that use the fields already
    matching_keysched = next(
        (
            x for x in all_schedules
            if x.Definition.IsKeySchedule
            and x.Definition.CategoryId == category.Id
        ),
        None
    )
    if matching_keysched:
        cfield = has_field_conflicts(matching_keysched.Definition, fields)
        if cfield:
            if forms.alert(
                    "Field \"{}\" is already used by another "
                    "key schedule \"{}\". Multiple key schedules can not "
                    "set values for same parameter. Do you want to delete "
                    "the existing key schedule first?".format(
                        cfield,
                        matching_keysched.Name
                        ),
                    yes=True, no=True):
                # the the process continue to check matching names below
                if not safe_delete_keysched(doc, matching_keysched):
                    return None

    # check for matching view names
    all_schedules = \
        revit.query.get_all_views(doc=doc, view_types=[DB.ViewType.Schedule])
    existing_view = \
        revit.query.get_view_by_name(sched_name,
                                     view_types=[DB.ViewType.Schedule])
    if existing_view:
        if isinstance(existing_view, DB.ViewSchedule) \
                and existing_view.Definition.IsKeySchedule \
                and existing_view.Definition.CategoryId == category.Id:
            if forms.alert(
                    "There is a \"{}\" key schedule with name \"{}\". "
                    "Do you want to delete this first?".format(
                        category.Name,
                        sched_name),
                    yes=True, no=True):
                if safe_delete_keysched(doc, existing_view):
                    return sched_name
        else:
            if forms.alert(
                    "There is a view with the same name \"{}\" but it is "
                    "not a key schedule! Do you want to choose a new name "
                    "for this key schedule?"
                    .format(sched_name),
                    yes=True, no=True):
                return forms.ask_for_unique_string(
                    reserved_values=[x.Name for x in all_schedules],
                    default='{} {}'.format(sched_name, coreutils.current_date())
                )
        return None
    return sched_name