Python script and list problem

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

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

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!

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.

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.

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.

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)
1 Like

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!

You mean sublists are like the below image, right?

q1

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.