Created
March 4, 2021 22:14
-
-
Save johnpierson/6caafb9ad7c4fcf811b4bac18b001701 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import clr | |
| clr.AddReference('System') | |
| from System.Collections.Generic import List | |
| clr.AddReference('RevitAPI') | |
| from Autodesk.Revit.DB import * | |
| from Autodesk.Revit.DB.Structure import * | |
| clr.AddReference('RevitNodes') | |
| import Revit | |
| clr.ImportExtensions(Revit.GeometryConversion) | |
| clr.ImportExtensions(Revit.Elements) | |
| clr.AddReference('RevitServices') | |
| import RevitServices | |
| from RevitServices.Persistence import DocumentManager | |
| from RevitServices.Transactions import TransactionManager | |
| doc = DocumentManager.Instance.CurrentDBDocument | |
| uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument | |
| #allows us to loop it. we are expecting sublists in this case | |
| def CreateGroup(items): | |
| for e in items: | |
| ids = [] | |
| ids.append(e.Id) | |
| col = List[ElementId](ids) | |
| t = Transaction(doc,"group") | |
| TransactionManager.Instance.ForceCloseTransaction() #force close dynamo's auto refresh transaction | |
| t.Start() | |
| group = doc.Create.NewGroup(col) | |
| t.Commit() | |
| return group.ToDSType(True) | |
| #our sublists | |
| elements = UnwrapElement(IN[0]) | |
| #for output | |
| newGroups = [] | |
| #transaction group encapsulates all the changes | |
| tg = TransactionGroup(doc,"OverallTransaction") | |
| tg.Start() | |
| for e in elements: | |
| newGroups.append(CreateGroup(e)) | |
| #now refresh | |
| tg.Assimilate() | |
| OUT = newGroups |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment