How to get curves from surface in python

Hi All,
After exploding my solid geometry I get surfaces, and I want to get curves from these surfaces, so what’s wrong in my code below?

import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import *

[Shaft_Geo] = Element.Geometry(IN[0])
Shaft_Surfaces = Geometry.Explode(Shaft_Geo)


OUT = Surface.PerimeterCurves([Shaft_Surfaces])

Thanks.

The error tells you that the method expects a Surface but was given a List. In the last line you wrap Shaft_Surfaces in a list. That’s causing you problems. Just pass the surface as-is.

2 Likes

Hello,
here is

import sys
import clr

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

clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import*

geo=Element.Geometry(IN[0])
surf=Geometry.Explode(geo[0])
curv=[Surface.PerimeterCurves(s) for s in surf]

OUT = geo,surf,curv

Cordially
christian.stan

1 Like

@Nick_Boyts @christian.stan

This is an never ending Shaft :grin:

I got all my curves listed as shown below:

Now I want to get the length of each curve and keep the structure of my main list and the nested sublists, but I get the error message below

What’s wrong in my code here?

import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import *


Geo = Element.Geometry(IN[0])
Surf = Geometry.Explode(Geo[0])
Curvs = [Surface.PerimeterCurves(i) for i in Surf]

for i in Curvs:
    for j in i:
        Curv_length = [Curve.Length(j)]
        
OUT = Curv_length

Thanks.

Hello, here,
You forgot a container
It must have been faster for sure.

import sys
import clr

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

clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import*

geo=Element.Geometry(IN[0])
surf=Geometry.Explode(geo[0])
curv=[Surface.PerimeterCurves(s) for s in surf]

#You need an empty container to store your loop result
length_c=[]
temp=[]

for level_list in range(0,len(curv)):
    for c in curv[level_list]:
        temp.append(c.Length)
    length_c.append(temp)
    temp=[]

OUT = geo,surf,curv,length_c

edit: Don’t take this as a presumptuous message from me :wink:
check out this very informative post
Clear and instructive instruction

I love women, don’t worry Mr. Sol Amour :wink:

Cordially
christian.stan

1 Like

@christian.stan

Thanks Christian

Can you rewrite the whole code in a single line using enumerate or zip function? (just for another option)

for level_list in range(0,len(curv)):
    for c in curv[level_list]:
        temp.append(c.Length)
    length_c.append(temp)
    temp=[]

Thanks.