profile family to ds polycurve
By [Konrad K Sobon](/content/author/ksobon/ "Posts by Konrad K Sobon"/index.html)/06 Sep 2014/
image by selux lookbook
This past week I have ran into a post on the DynamoBIM blog that was asking about an easier way to get profiles from Revit into Dynamo so that they can be used as Profiles while doing sweeps and extrusions like in this example by Eduardo Roca. As you can see Eduardo is going to some painstaking lengths to convert a profile into a PolyCurve that can be used with a Sweep node. As much as I like his write up I hate to do all of this manual labor of re drawing everything in Revit with model lines and then importing into Dynamo via Element Selection node.
In order to solve that problem I have created a node that queries a Profile Family and extracts its geometry (curves) while converting them to PolyCurves or Lists of Lists containing Curve segments as Lines or Arcs. This streamlines the process of creating a PolyCurve to creating a Profile Family and loading it into a project then selecting it using Family Types node in Dynamo.
The gist of this node is its geometry extraction that is done taking advantage of RevitAPI’s family management tools. When we create a Profile Family it is stored in that family’s document under Sketch class and then further under Profile as a CurveArray. The nice thing about that is that CurveArrays are nicely organized into lists of lists containing curves for each closed loop. That makes it much easier to convert to DS geometry and still keep nicely organized.
Here’s the code for this node:
#Copyright(c) 2014, Konrad Sobon
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
# The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
name = str(IN[0].Name)
# Select family instance by name
collector = FilteredElementCollector(doc)
families = collector.OfClass(Family)
for i in families:
if i.Name == name:
family = i
break
else:
continue
# Extract profile curves from family(sketch)
famDoc = doc.EditFamily(family)
famCollector = FilteredElementCollector(famDoc)
sketch = famCollector.OfClass(Sketch)
# Convert Revit geometry to DS Geometry (lines, arc etc)
for i in sketch:
cArray = list(i.Profile)
cArray[:] = [[Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(y, True) for y in x] for x in cArray]
# Assign your output to the OUT variable
OUT = cArray
Here’s an example of possible use for this node:
PolyCurve from Profile Family Type can be downloaded [here](/content/?page_id=47 "Dynamo"/index.html).