Creates a new FillPatternElement.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 23.0.0.0 (23.1.0.0)
Since: 2012
Syntax
C# |
---|
public static FillPatternElement Create( Document document, FillPattern fillPattern ) |
Visual Basic |
---|
Public Shared Function Create ( _ document As Document, _ fillPattern As FillPattern _ ) As FillPatternElement |
Visual C++ |
---|
public: static FillPatternElement^ Create( Document^ document, FillPattern^ fillPattern ) |
Parameters
- document
- Type: Autodesk.Revit.DB..::..Document
The document in which to create the FillPatternElement.
- fillPattern
- Type: Autodesk.Revit.DB..::..FillPattern
The FillPattern associated to the newly created FillPatternElement.
Return Value
The newly created FillPatternElement.
Examples

// Create a complex fill pattern public void CreateComplexFillPattern(Document doc) { // Create the fill pattern FillPattern fillPattern = new FillPattern("API-created", FillPatternTarget.Model, FillPatternHostOrientation.ToHost); // Add grids List<FillGrid> grids = new List<FillGrid>(); //Horizontal lines. // The arguments: origin, offset (vertical distance between lines), // angle, shift (delta between location of start point per line) // The last two arguments are the segments: e.g. 1.0 units on, // 0.1 units off (units are Revit units (ft)) grids.Add(CreateGrid(new UV(0, 0.1), 0.5, 0, 0.55, 1.0, 0.1)); grids.Add(CreateGrid(new UV(0, 0.5), 0.5, 0, 0.55, 1.0, 0.1)); // Vertical lines. grids.Add(CreateGrid(new UV(0, 0.1), 0.55, Math.PI / 2, 0.5, 0.4, 0.6)); grids.Add(CreateGrid(new UV(1.0, 0.1), 0.55, Math.PI / 2, 0.5, 0.4, 0.6)); fillPattern.SetFillGrids(grids); // Create the fill pattern element. Now document is modified; transaction is needed using (Transaction t = new Transaction(doc, "Create fill pattern")) { t.Start(); FillPatternElement patternElement = FillPatternElement.Create(doc, fillPattern); t.Commit(); } } // Creates and returns a new fill grid private FillGrid CreateGrid(UV origin, double offset, double angle, double shift, params double[] segments) { FillGrid fillGrid = new FillGrid(); fillGrid.Origin = origin; fillGrid.Offset = offset; fillGrid.Angle = angle; fillGrid.Shift = shift; List<double> segmentsList = new List<double>(); foreach (double d in segments) { segmentsList.Add(d); } fillGrid.SetSegments(segmentsList); return fillGrid; }

' Create a complex fill pattern Public Sub CreateComplexFillPattern(doc As Document) ' Create the fill pattern Dim fillPattern As New FillPattern("API-created", FillPatternTarget.Model, FillPatternHostOrientation.ToHost) ' Add grids Dim grids As New List(Of FillGrid)() 'Horizontal lines. ' The arguments: origin, offset (vertical distance between lines), ' angle, shift (delta between location of start point per line) ' The last two arguments are the segments: e.g. 1.0 units on, ' 0.1 units off (units are Revit units (ft)) grids.Add(CreateGrid(New UV(0, 0.1), 0.5, 0, 0.55, 1.0, 0.1)) grids.Add(CreateGrid(New UV(0, 0.5), 0.5, 0, 0.55, 1.0, 0.1)) ' Vertical lines. grids.Add(CreateGrid(New UV(0, 0.1), 0.55, Math.PI / 2, 0.5, 0.4, 0.6)) grids.Add(CreateGrid(New UV(1.0, 0.1), 0.55, Math.PI / 2, 0.5, 0.4, 0.6)) fillPattern.SetFillGrids(grids) ' Create the fill pattern element. Now document is modified; transaction is needed Using t As New Transaction(doc, "Create fill pattern") t.Start() Dim patternElement As FillPatternElement = FillPatternElement.Create(doc, fillPattern) t.Commit() End Using End Sub ' Creates and returns a new fill grid Private Function CreateGrid(origin As UV, offset As Double, angle As Double, shift As Double, ParamArray segments As Double()) As FillGrid Dim fillGrid As New FillGrid() fillGrid.Origin = origin fillGrid.Offset = offset fillGrid.Angle = angle fillGrid.Shift = shift Dim segmentsList As New List(Of Double)() For Each d As Double In segments segmentsList.Add(d) Next fillGrid.SetSegments(segmentsList) Return fillGrid End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions..::..ArgumentException | fillPattern does not have a valid Target. -or- fillPattern does not have a valid Name. -or- fillPattern is a solid fill pattern. -or- fillPattern contains FillGrids with a zero Offset. -or- The name of the fillPattern already exists. |
Autodesk.Revit.Exceptions..::..ArgumentNullException | A non-optional argument was null |