Hello. New to Dynamo here so go easy please.
I am hoping that I can use Dynamo to achieve the following - opening each family loaded into a model, ungrouping all elements, purging, and loading them back into the model. Am I being too optimistic?
This is because a job we’re working on has got 2300+ families loaded - it is a historic building with a lot of bespoke content. The company who produced the point cloud based 3D survey grouped all elements in each family before saving it. I have worked out that this has caused each family to have a file size increase of anything from 20% to sometimes 70%, had the elements not been grouped! Considering the amount of content loaded, I figure this is having a pretty big impact on the model size and workflow on the whole team, who will be using this model daily for years to come.
I am hoping Dynamo will be our way out of this… any help would be much appreciated!
Usually, proceeding step by step leads to results. You can surely ask for help on the particular issues you encounter when building your graph. The forum guidelines are clearly explaining how to do this (point 7 is quite explicit, I think)
They are, and I didn’t really expect to have work done for me, was quite genuinely wondering whether it’s the type of thing it would do or not. Thanks for your help though!
OK, this topic could possibly go further, so here is a way to get started: Group.UngroupElements is from Rhythm or Clockwork.
Please use with caution and do some preliminary tests (don’t run in automatic or several times and use Undo in Revit if needed)
"Usually, proceeding step by step leads to results"
Usually not. Thus, your next post about ungrouping is a good example - it works only with elements in the model.
The original topic is much trickier - how to process families and work inside them as we do in models. Look fwd to gurus.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic 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
#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0])
path = IN[1]
for e in elements:
famdoc = doc.EditFamily(e)
fec = FilteredElementCollector(famdoc).OfCategory(BuiltInCategory.OST_IOSModelGroups).WhereElementIsNotElementType()
if fec.FirstElement() is not None:
groups = fec.ToElements()
TransactionManager.Instance.EnsureInTransaction(famdoc)
[g.UngroupMembers() for g in groups]
TransactionManager.Instance.ForceCloseTransaction()
famdoc.SaveAs(path +"\\" + e.Name + ".rfa")
OUT = 0
Yes, you have to use that as an argument in one of the overloads of the LoadFamily Method. It requires that you create a custom class and maybe utilize StrongBox type to handle the out attributes in that class’ methods. That shouldn’t be any problem, but I had some doubt about the transactions, but it can probably be handled with ForceCloseTransaction() in the Transaction manager.
Here is the call of the LoadFamily method call on the familydocument:
famdoc.LoadFamily(doc, FamilyOption())
@luisa Do you want to test the script? It doesn’t purge anything, because that has to be done manually. There is no API call to the purge command in Revit.