# Managed exception thrown by Revit/other app - Filled Region Creation via Python

**URL:** <https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388>\
**Category:** Developers\
**Tags:** python, dynamo\
**Created:** [June 19, 2019, 7:29pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388 "2019-06-19T19:29:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![colby.evans](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@colby.evans](https://forum.dynamobim.com/u/colby.evans)\
**Post date:** [June 19, 2019, 7:29pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388/1 "2019-06-19T19:29:07Z")

</div>

I am getting an exception thrown from trying to create a filled region; I would like some understanding to the cause, and idea for considering solutions to problem.

Regards,

“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.  
Traceback (most recent call last):  
File “”, line 21, in   
Exception: A managed exception was thrown by Revit or by one of its external applications.”

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/5/651ec379a33a7aef095f0fb19bbdec5741b8e303.png)

---

<div class="post-metadata">

**Author:** ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)\
**Post date:** [June 19, 2019, 8:30pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388/2 "2019-06-19T20:30:33Z")

</div>

Is there a reason why you aren’t using the OOTB node for this?  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b4eb9ff9b9ff41debe805959aae2782ddca82f66.png)

It would be much more helpful to share an image of the graph and/or the actual graph. There are too many variables here to guess at.

---

<div class="post-metadata">

**Author:** ![colby.evans](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@colby.evans](https://forum.dynamobim.com/u/colby.evans)\
**Post date:** [June 19, 2019, 8:47pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388/3 "2019-06-19T20:47:25Z")

</div>

I tried to at first, but every type of “regionType” would turn up an error.

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

Warning: One or more of the input types are not matching. Couldn’t find a version of ByCurves that takes arguments of type (Function,\_\_array,Revit.Elements.FilledRegionType)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 19, 2019, 8:48pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388/4 "2019-06-19T20:48:12Z")

</div>

You don’t have a view. Document.ActiveView requires a doc input.  
I also don’t remember if your boundary input has to be a closed polycurve or separate curves, but order would likely matter in the case of the latter.

---

<div class="post-metadata">

**Author:** ![colby.evans](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@colby.evans](https://forum.dynamobim.com/u/colby.evans)\
**Post date:** [June 19, 2019, 8:51pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388/5 "2019-06-19T20:51:43Z")

</div>

The document was the issue for the OOTB node.

---

<div class="post-metadata">

**Author:** ![Alban\_de\_Chasteigner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alban_de_chasteigner/32/39650_2.png) [@Alban\_de\_Chasteigner](https://forum.dynamobim.com/u/Alban_de_Chasteigner)\
**Post date:** [June 19, 2019, 9:21pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388/6 "2019-06-19T21:21:50Z")

</div>

You need to make a curveloop with the API and retrieve a FilledRegionType.

```
import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

boundaryCurves = IN[0]
filledRegionName = IN[1]

viewId = doc.ActiveView.Id

TransactionManager.Instance.EnsureInTransaction(doc)
for col in FilteredElementCollector(doc).OfClass(FilledRegionType):
	if Element.Name.GetValue(col) == filledRegionName:
		regionId = col.Id

curveLoop=[]
filledCurves = CurveLoop()
for curve in boundaryCurves:
	filledCurves.Append(curve.ToRevitType())
curveLoop.Add(filledCurves)

outRegion = FilledRegion.Create(doc, regionId, viewId, curveLoop)
TransactionManager.Instance.TransactionTaskDone()

OUT = outRegion 	

```

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

---

<div class="post-metadata">

**Author:** ![colby.evans](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@colby.evans](https://forum.dynamobim.com/u/colby.evans)\
**Post date:** [June 19, 2019, 10:22pm UTC](https://forum.dynamobim.com/t/managed-exception-thrown-by-revit-other-app-filled-region-creation-via-python/37388/7 "2019-06-19T22:22:35Z")

</div>

Alban,

Thank you, this solved the issue, and gave me some more insight to the expecation of Revit’s wants for particular elements to satisfy its commands.

Regards,  
Colby Evans
