Ejemplo n.º 1
0
class ActionGroup():
    def __init__(self, name=None, assimilate=True):
        self._rvt_transaction_group = TransactionGroup(
            self.doc, name if name else DEFAULT_TRANSACTION_NAME)
        self.assimilate = assimilate

    def __enter__(self):
        self._rvt_transaction_group.Start()
        return self

    def __exit__(self, exception, exception_value, traceback):
        if exception:
            self._rvt_transaction_group.RollBack()
            logger.error('Error in TransactionGroup Context: has rolled back.')
            logger.error('{}:{}'.format(exception, exception_value))
        else:
            try:
                if self.assimilate:
                    self._rvt_transaction_group.Assimilate()
                else:
                    self._rvt_transaction_group.Commit()
            except Exception as errmsg:
                self._rvt_transaction_group.RollBack()
                logger.error(
                    'Error in TransactionGroup Commit: has rolled back.')
                logger.error('Error: {}'.format(errmsg))

    @property
    def name(self):
        return self._rvt_transaction_group.GetName()

    @name.setter
    def name(self, new_name):
        return self._rvt_transaction_group.SetName(new_name)

    @property
    def status(self):
        return ActionStatus.from_rvt_trans_stat(
            self._rvt_transaction_group.GetStatus())

    def has_started(self):
        return self._rvt_transaction_group.HasStarted()

    def has_ended(self):
        return self._rvt_transaction_group.HasEnded()
Ejemplo n.º 2
0
def main():
    pipes = FilteredElementCollector(doc)\
        .OfCategory(BuiltInCategory.OST_PipeCurves)\
        .WhereElementIsNotElementType().ToElements()
    pipes = [
        pipe for pipe in pipes
        if '{}'.format(pipe.LookupParameter('Длина').AsDouble() *
                       k) != pipe.LookupParameter('Длина старая').AsString()
    ]

    tg = TransactionGroup(doc, "Длина петли")
    tg.Start()
    t = Transaction(doc, "blabla")
    t.Start()

    [
        pipe.LookupParameter('Длина старая').Set('{}'.format(
            pipe.LookupParameter('Длина').AsDouble() * k)) for pipe in pipes
    ]

    global handledElems
    handledElems = []
    global tabs
    global OUT
    siblingGroups = []
    for pipe in pipes:
        siblings = []
        if pipe.Id.ToString() not in handledElems:
            handledElems.append(pipe.Id.ToString())
            tabs = 1
            siblings = getSiblings(pipe)
            siblingGroups.append(siblings)

    for group in siblingGroups:
        s = sum([
            e.LookupParameter('Длина').AsDouble() * k for e in group
            if e.LookupParameter('Длина')
        ])
        for el in group:
            el.LookupParameter('Длина петли').Set('{:.0f}'.format(
                s / 1000).replace('.', ','))

    t.Commit()
    tg.Assimilate()
Ejemplo n.º 3
0
class ActionGroup:
    def __init__(self, name=None, assimilate=True):
        self.transaction_group = TransactionGroup(doc, name if name else DEFAULT_TRANSACTION_NAME)
        self.assimilate = assimilate

    def __enter__(self):
        self.transaction_group.Start()
        return self.transaction_group

    def __exit__(self, exception, exception_value, traceback):
        if exception:
            self.transaction_group.RollBack()
            logger.error('Error in TransactionGroup Context: has rolled back.')
            logger.error('{}:{}'.format(exception, exception_value))
        else:
            try:
                if self.assimilate:
                    self.transaction_group.Assimilate()
                else:
                    self.transaction_group.Commit()
            except Exception as errmsg:
                self.transaction_group.RollBack()
                logger.error('Error in TransactionGroup Commit: has rolled back.')
                logger.error('Error: {}'.format(errmsg))
Ejemplo n.º 4
0
__author__ = 'Ehsan Iran-Nejad'

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Transaction, TransactionGroup

doc = __revit__.ActiveUIDocument.Document

sheets_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets) \
                                                .WhereElementIsNotElementType() \
                                                .ToElements()

wall_id_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls) \
                                              .WhereElementIsNotElementType() \
                                              .ToElementIds()

tg = TransactionGroup(doc, "Update and Delete")
tg.Start()

t = Transaction(doc, "Update Sheet Parmeters")
t.Start()

for sheet in sheets_collector:
    custom_param = sheet.LookupParameter('Comments')
    if custom_param:
        custom_param.Set("Example value")

t.Commit()

t = Transaction(doc, "Deleting All Walls")
t.Start()

for wall_id in wall_id_collector: