Floor contour and location with Python

Hi everyone,
I was trying to get a floor outline contour, assuming it worked just like a wall (or other line driven elements) location curve.
However, the locations I extract with Python are neither curves nor points. When applied to floors, the Element.GetLocation node gives an error as well.

So, does anyone have an idea how to get a floor contour with the API?

Thanks!

It’s a bit tricky but it’s doable with a workaround.

If you use doc.Delete() on the floor you get the list of deleted elements as return. There you will find all the lines that make the floor sketch. Roll back the transaction to un-delete the floor.

1 Like

Oh god… I knew floors were trouble :slight_smile:
How do I roll a transaction back within the same script?

Here is a snipped of the code I use to get the floor contours.

trans = Autodesk.Revit.DB.Transaction(doc, "Temp Transaction")

trans.Start()

delel = doc.Delete(slab.Id)

trans.RollBack()
1 Like

Works like a charm.
Thank you!

In the springs package there is a node called “Springs.Collector.ElementSketch”. This will return the lines that form the floor. Might be a bit easier to use that instead.

2 Likes

Thanks, but I’m making an effort to stick to the API. Hope it’s gonna pay off in the long run.

1 Like

@mikael_deity
Thanks for you code in advance, but I encounter a problem that expect ElementId ,got int
Actually, I know the object type of ElementId is int, but is it the wrong input which the function need??

In my code, I choose a slab element for testing.

list_slab = UnwrapElement(IN[2])

1 Like

@hctungBHP7B ElementId is of type ElementId. If you are passing integers, use the constructor of ElementId

check here: Revit API ElementId

value = 123
id = ElementId(value)

I have changed approach for this problem and use the top host faces perimeters that can be extracted with the API

code below:

# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit

# Import Revit elements
from Revit.Elements import *

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

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

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

import System

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

# Place your code below this line

floor = UnwrapElement(IN[0])

references = HostObjectUtils.GetTopFaces(floor)

faces = []

for reference in references:
    faces.extend(floor.GetGeometryObjectFromReference(reference).ToProtoType())

curves = []

for face in faces:
    curves.append(face.PerimeterCurves())

# Assign your output to the OUT variable.
OUT = curves

1 Like

@Deniz_Maral
Thank you so much, I will try out.

@mikael_deity
Especially, Thank you for your comprehensive reply and also provide the reference of ElementId knowhow. I will try later.