Exemplo 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()
Exemplo n.º 2
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))
__doc__ = 'Lists all the elements that are tied to the selected element. For example elements tags or dimensions.'

from Autodesk.Revit.DB import Transaction, TransactionGroup

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = __revit__.ActiveUIDocument.Selection.GetElementIds()

tg = TransactionGroup(doc, "Search for linked elements")
tg.Start()
t = Transaction(doc, "Search for linked elements")
t.Start()

linkedelementslist = []

for elId in selection:
    print("Searching for all objects tied to ELEMENT ID: {0}...".format(elId))
    linkedelementslist = doc.Delete(elId)

t.Commit()
tg.RollBack()

for elId in linkedelementslist:
    el = doc.GetElement(elId)
    if el and elId in selection:
        print("ID: {0}\t\tTYPE: {1} ( selected object )".format(
            elId,
            el.GetType().Name))
    elif el:
        print("ID: {0}\t\tTYPE: {1}".format(elId, el.GetType().Name))