# Ungrouping & Purging All Families in a Model

**URL:** <https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210>\
**Category:** Revit\
**Tags:** revit\
**Created:** [December 13, 2016, 12:32pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210 "2016-12-13T12:32:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![luisa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luisa/32/18196_2.png) [@luisa](https://forum.dynamobim.com/u/luisa)\
**Post date:** [December 13, 2016, 12:32pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/1 "2016-12-13T12:32:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [December 13, 2016, 4:28pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/2 "2016-12-13T16:28:40Z")

</div>

Hello, please take a look at this discussion:

> [@Editing Revit Groups with Dynamo](https://forum.dynamobim.com/t/editing-revit-groups-with-dynamo/7736/14):
>
> Maybe this can help: This was a test challenge i got from a colleague, so its probably gonna need some tweaking. The challenge was to change a yes/no parameter of an instance of a door type, which is in a model group, in a project containing two instances of the same group. The first python-script collects all groups in the project: import clr clr.AddReference('ProtoGeometry') from Autodesk.DesignScript.Geometry import \* #Import the Revit API clr.AddReference('…

---

<div class="post-metadata">

**Author:** ![Nikolay\_Gerasimov1](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@Nikolay\_Gerasimov1](https://forum.dynamobim.com/u/Nikolay_Gerasimov1)\
**Post date:** [February 6, 2017, 11:13am UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/3 "2017-02-06T11:13:23Z")

</div>

Any updates to the post? How to batch processing families inside a model (purge them particularly)?

---

<div class="post-metadata">

**Author:** ![luisa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luisa/32/18196_2.png) [@luisa](https://forum.dynamobim.com/u/luisa)\
**Post date:** [February 13, 2017, 2:50pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/4 "2017-02-13T14:50:53Z")

</div>

Unfortunately no!  
The thread suggested above does not cover this particular issue of purging families.

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [February 13, 2017, 3:58pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/5 "2017-02-13T15:58:54Z")

</div>

This thread could help to to get the answers you need:

> [@How to get help on the Dynamo forums](https://forum.dynamobim.com/t/how-to-get-help-on-the-dynamo-forums/4677):
>
> One of the main goals of the Dynamo community is to help others. One way to do that is by answering your questions. But to get the right answer, you’ll first have to ask your question in the right way. Although people are generally very helpful, there are things you can do to improve your chances of getting good and quick answers. Below you will find some suggestions on how to achieve that. Do not think of these suggestions as rules and especially do not take them as a guarantee of getting an an…

---

<div class="post-metadata">

**Author:** ![luisa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luisa/32/18196_2.png) [@luisa](https://forum.dynamobim.com/u/luisa)\
**Post date:** [February 13, 2017, 4:25pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/6 "2017-02-13T16:25:06Z")

</div>

Fair enough!  
Long story short, this is what I need Dynamo to do:

- open each family loaded into a model,
- ungroup all elements within that family,
- purge family,
- load back into the model

Possibly a big ask.

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [February 13, 2017, 4:35pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/7 "2017-02-13T16:35:02Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![luisa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luisa/32/18196_2.png) [@luisa](https://forum.dynamobim.com/u/luisa)\
**Post date:** [February 13, 2017, 4:48pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/8 "2017-02-13T16:48:21Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [February 13, 2017, 8:35pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/9 "2017-02-13T20:35:22Z")

</div>

OK, this topic could possibly go further, so here is a way to get started:  
 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/2/f27669fdc31a98dbfeac820e80ecbd782c5f8c73.JPG)  
_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)

---

<div class="post-metadata">

**Author:** ![luisa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luisa/32/18196_2.png) [@luisa](https://forum.dynamobim.com/u/luisa)\
**Post date:** [February 14, 2017, 10:07am UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/10 "2017-02-14T10:07:35Z")

</div>

Oooo. Thank you for this, will see how I get on and report back!

---

<div class="post-metadata">

**Author:** ![Nikolay\_Gerasimov1](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@Nikolay\_Gerasimov1](https://forum.dynamobim.com/u/Nikolay_Gerasimov1)\
**Post date:** [February 15, 2017, 4:52pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/11 "2017-02-15T16:52:50Z")

</div>

"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.

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [February 15, 2017, 5:50pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/12 "2017-02-15T17:50:09Z")

</div>

@Nikolay_Gerasimov1  
[https://forum.dynamobim.com/faq](https://forum.dynamobim.com/faq)

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [February 15, 2017, 8:25pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/13 "2017-02-15T20:25:02Z")

</div>

Here is a start on how to open, ungroup and save the families. I 'm not sure if it’s possible to reload the documentes with Dynamo.

[WIP-open family and ungroup.dyn](https://forum.dynamobim.com/uploads/short-url/kYyJb6Zncbj8sHTKb1D58zyGlEy.dyn) (6.3 KB)

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/5/d516989f5df72388716a174676cddf993b20d75a.png)

```
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
```

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [February 16, 2017, 3:54am UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/14 "2017-02-16T03:54:02Z")

</div>

> [@Einar\_Raknes](#):
>
> I 'm not sure if it’s possible to reload the documentes with Dynamo.

You can use IFamilyLoadOptions Interface in Revit API [IFamilyLoadOptions Interface](http://www.revitapidocs.com/2017/d447ed92-74e1-2125-dd0a-38a5ae85ce53.htm)

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [February 16, 2017, 11:23am UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/15 "2017-02-16T11:23:44Z")

</div>

Yes, you have to use that as an argument in one of the overloads of the [LoadFamily Method](http://www.revitapidocs.com/2017/cb950c8e-f440-c6db-8563-d1dd16ef3fee.htm). It requires that you create a custom class and maybe utilize [StrongBox type](https://msdn.microsoft.com/en-us/library/bb549038(v=vs.110).aspx) 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 a C# example:

> **[Reloading a Family](http://thebuildingcoder.typepad.com/blog/2011/06/reloading-a-family.html#3)**
>
> Here is an impressively complete list of pretty fundamental beginner's issues that you might potentially run into when reloading a family, starting from scratch, from a recent case handled by my colleague Joe Ye. One of the interesting points that...

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [February 16, 2017, 7:45pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/16 "2017-02-16T19:45:48Z")

</div>

I found some time to take a look at the reloading:

The IFamilyLoadOptions implemented in python:

```
class FamilyOption(IFamilyLoadOptions):
	def OnFamilyFound(self,familyInUse,overwriteParameterValues):
		overwriteParameterValues = True
		return True
		
	def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
		return True

```

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.

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/5/a50a7d09dec8297562dceed1b1afd4f687cfbca7.png)

[OpenAndUngroupFamilies.dyn](https://forum.dynamobim.com/uploads/short-url/rw94M28mnrYbha2xSBaQ1eFxFXz.dyn) (6.1 KB)

For anyone that might be interested,.the complete python script:

```
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

class FamilyOption(IFamilyLoadOptions):
	def OnFamilyFound(self,familyInUse,overwriteParameterValues):
		overwriteParameterValues = True
		return True
		
	def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
		return True
		
#Preparing input from dynamo to revit
families = UnwrapElement(IN[0])

for f in families:
	famdoc = doc.EditFamily(f)
	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.TransactionTaskDone()
		TransactionManager.Instance.ForceCloseTransaction()
		
		TransactionManager.Instance.EnsureInTransaction(doc)
		famdoc.LoadFamily(doc, FamilyOption())
		TransactionManager.Instance.TransactionTaskDone()
		TransactionManager.Instance.ForceCloseTransaction()
		
		#famdoc.SaveAs(path +"\\" + e.Name + ".rfa")
OUT = 0
```

---

<div class="post-metadata">

**Author:** ![luisa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luisa/32/18196_2.png) [@luisa](https://forum.dynamobim.com/u/luisa)\
**Post date:** [February 17, 2017, 4:52pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/17 "2017-02-17T16:52:55Z")

</div>

@Einar_Raknes definitely but am snowed under with other work at the moment! I will report back once I find the time to dedicate to this. Many thanks!

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [February 18, 2017, 5:38am UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/18 "2017-02-18T05:38:17Z")

</div>

There was a similar question on how to edit multiple families quite a while ago, that was answered here:

> [@Modify Room Calculation Point toggle (Builtin Parameter)](https://forum.dynamobim.com/t/modify-room-calculation-point-toggle-builtin-parameter/1909/6):
>
> Jeff, Does this work for you? [Capture]Here is how this works. You take a family that you want to override and place it in the folder. You can place multiple families in there if you want to override this parameter for all of them. Use Directory.Contents to get all the family paths and feed that into Python node. Then also feed it a BuiltInParameter name as a string, and a value that you wan this parameter to be overridden to. Hit Run and what will happen is that it will change that one param…

It might give you some more examples to work with, but you might need to dig the old forum for the full-rez images.

---

<div class="post-metadata">

**Author:** ![Nikolay\_Gerasimov1](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@Nikolay\_Gerasimov1](https://forum.dynamobim.com/u/Nikolay_Gerasimov1)\
**Post date:** [February 20, 2017, 3:56pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/19 "2017-02-20T15:56:47Z")

</div>

> [@Einar\_Raknes](#):
>
> There is no API call to the purge command in Revit.

This is what I wanted to know. Thx.

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [February 20, 2017, 5:39pm UTC](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210/20 "2017-02-20T17:39:18Z")

</div>

You can still purge e.g. unused families with dynamo: [http://whatrevitwants.blogspot.no/2015/11/purge-component-families-using.html](http://whatrevitwants.blogspot.no/2015/11/purge-component-families-using.html)

[Next page](https://forum.dynamobim.com/t/ungrouping-purging-all-families-in-a-model/8210.md?page=2)
