RevitPythonShell: Divided Surface
<<< Return to Nathan's Revit API Notebook
Introduction
This section will demonstrate how to create and modify divided surfaces using the API. Divided surfaces allow us to create patterns and paneling systems on complex forms. Please note that divided surfaces only work within the conceptual mass environment.
Dividing a Surface
To divide a surface we will use FamilyCreate.NewDividedSurface(). We can establish U and V spacing with the properties USpacingRule and VSpacingRule.
import clr clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import * app = __revit__.Application doc = __revit__.ActiveUIDocument.Document t = Transaction(doc, 'Divide Surface.') t.Start() #Create a FilteredElementCollector collector = FilteredElementCollector(doc) collector.OfCategory(BuiltInCategory.OST_MassForm) famtypeitr = collector.GetElementIdIterator() famtypeitr.Reset() for item in famtypeitr: typeID = item srfObj = doc.get_Element(typeID) #Get Geometry Elements geOptions = app.Create.NewGeometryOptions() geOptions.ComputeReferences = True geoElem = srfObj.get_Geometry(geOptions) #For each geometry object in geometry elements for geObj in geoElem.Objects: #For each face on the geometry object for face in geObj.Faces: #Divide the face divSrf = doc.FamilyCreate.NewDividedSurface(face.Reference) #Establish spacing rules srfU = divSrf.USpacingRule srfU.SetLayoutFixedNumber(20, SpacingRuleJustification.Center,0,0) srfV = divSrf.VSpacingRule srfV.SetLayoutFixedNumber(20, SpacingRuleJustification.Center,0,0) t.Commit() __window__.Close()
Assigning a Pattern
We can change the type of divided surface by changing the type ID of the tile pattern.
import clr clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import * app = __revit__.Application doc = __revit__.ActiveUIDocument.Document t = Transaction(doc, 'Change surface pattern.') t.Start() #Create a FilteredElementCollector collector = FilteredElementCollector(doc) collector.OfCategory(BuiltInCategory.OST_MassForm) famtypeitr = collector.GetElementIdIterator() famtypeitr.Reset() for item in famtypeitr: typeID = item srfObj = doc.get_Element(typeID) #Tile pattern variable patterns = doc.Settings.TilePatterns #Divided surface data for a surface object. divSrfData = srfObj.GetDividedSurfaceData() for ref in divSrfData.GetReferencesWithDividedSurfaces(): divSrf = divSrfData.GetDividedSurfaceForReference(ref) #Change the surface pattern using a built in tile system. divSrf.ChangeTypeId(patterns.GetTilePattern(TilePatternsBuiltIn.TriangleCheckerboard_Flat).Id) t.Commit() __window__.Close()