# Python script and list problem

**URL:** <https://forum.dynamobim.com/t/python-script-and-list-problem/48004>\
**Category:** Developers\
**Tags:** python, dynamo\
**Created:** [March 12, 2020, 8:26am UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004 "2020-03-12T08:26:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamiel.Lee](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kamiel.Lee](https://forum.dynamobim.com/u/Kamiel.Lee)\
**Post date:** [March 12, 2020, 8:26am UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/1 "2020-03-12T08:26:14Z")

</div>

I’ve found Kulkul’s python code which gets curves from profile families.

> [@Creating a profile in Revit, and importing it as polycurve into dynamo](https://forum.dynamobim.com/t/creating-a-profile-in-revit-and-importing-it-as-polycurve-into-dynamo/521/19):
>
> Hi @mcooper4GXRR May be konrad is busy. You can try this script: import clr clr.AddReference('ProtoGeometry') from Autodesk.DesignScript.Geometry import \* # Import ToDSType(bool) extension method clr.AddReference("RevitNodes") import Revit clr.ImportExtensions(Revit.Elements) # Import DocumentManager and TransactionManager clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionM…

However, the problem is when it is connected with lists, it doesn’t work.

 ![error](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/c/9c4141dc86c7f1a38ccd2030277d1eb72fece99c.jpeg)

How should I modify the code to work?

Here are the Kulkul’s codes:

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

type = UnwrapElement(IN[0].Family.Name)
name = UnwrapElement(IN[0].Name)

family = UnwrapElement(IN[0]).Family

TransactionManager.Instance.ForceCloseTransaction()
famDoc = doc.EditFamily(family)

famCollector = FilteredElementCollector(famDoc)
sketch = famCollector.OfClass(Sketch)

for i in sketch:
	cArray = list(i.Profile)
cArray[:] = [[Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(y, True ) for y in x] for x in cArray]

```

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![AlexanderBerg](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alexanderberg/32/82944_2.png) [@AlexanderBerg](https://forum.dynamobim.com/u/AlexanderBerg)\
**Post date:** [March 12, 2020, 8:31am UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/2 "2020-03-12T08:31:56Z")

</div>

You feeding list. The script expects instance. Try feeding one instance and see if it works. If it does, then change your script to work with lists.

---

<div class="post-metadata">

**Author:** ![Kamiel.Lee](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kamiel.Lee](https://forum.dynamobim.com/u/Kamiel.Lee)\
**Post date:** [March 12, 2020, 8:46am UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/3 "2020-03-12T08:46:12Z")

</div>

It works fine for one instance. By the way I’m running on baby steps for python things so don’t know how I fix it that much.

---

<div class="post-metadata">

**Author:** ![Deniz\_Maral](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/deniz_maral/32/80323_2.png) [@Deniz\_Maral](https://forum.dynamobim.com/u/Deniz_Maral)\
**Post date:** [March 12, 2020, 8:53am UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/4 "2020-03-12T08:53:59Z")

</div>

You have to add a loop over families. Something like that:  
families=UnwrapElement[IN0]  
z=  
for fam in families:  
z.append(fam.Family)

and I see that you have sublists… you might have another loop for sublists. If that could be complicated you can flatten the list and do over one loop.

---

<div class="post-metadata">

**Author:** ![AlexanderBerg](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alexanderberg/32/82944_2.png) [@AlexanderBerg](https://forum.dynamobim.com/u/AlexanderBerg)\
**Post date:** [March 12, 2020, 12:04pm UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/5 "2020-03-12T12:04:12Z")

</div>

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

def Action(e):
    type = UnwrapElement(e.Family.Name)
    name = UnwrapElement(e.Name)

    family = UnwrapElement(e).Family

    TransactionManager.Instance.ForceCloseTransaction()
    famDoc = doc.EditFamily(family)

    famCollector = FilteredElementCollector(famDoc)
    sketch = famCollector.OfClass(Sketch)

    for i in sketch:
        cArray = list(i.Profile)
    cArray[:] = [[Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(y, True ) for y in x] for x in cArray]
    return cArray

OUT = []

for i in IN[0]:
    a = []
    for k in i:
        a.append(Action(k))
    OUT.append(a)
```

---

<div class="post-metadata">

**Author:** ![Kamiel.Lee](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kamiel.Lee](https://forum.dynamobim.com/u/Kamiel.Lee)\
**Post date:** [March 12, 2020, 11:55pm UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/6 "2020-03-12T23:55:07Z")

</div>

Wow, thank you to make me dive into your solution.  
Unfortunately, it looks something wrong with it yet on my side.  
Should I some codes fix?

Thanks a lot!

 ![e2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/f/9ff81dca50e6a9e36861dcb56bd986caafaedf50.png)

---

<div class="post-metadata">

**Author:** ![Kamiel.Lee](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kamiel.Lee](https://forum.dynamobim.com/u/Kamiel.Lee)\
**Post date:** [March 13, 2020, 12:01am UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/7 "2020-03-13T00:01:50Z")

</div>

You mean sublists are like the below image, right?

![q1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/4/54ef2cff20c541eb663a6e1c363ccda8850d459e.png)

---

<div class="post-metadata">

**Author:** ![Deniz\_Maral](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/deniz_maral/32/80323_2.png) [@Deniz\_Maral](https://forum.dynamobim.com/u/Deniz_Maral)\
**Post date:** [March 13, 2020, 8:31am UTC](https://forum.dynamobim.com/t/python-script-and-list-problem/48004/8 "2020-03-13T08:31:55Z")

</div>

Yes, that is right. You can flatten and loop over all items or create a custom node and use levels. There are many solution to that.
