Revit 2024 API |
Document..::..Paint Method (ElementId, Face, ElementId) |
Document Class Example See Also |
Paint the element's face with specified material.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:
2014
Syntax
C# |
---|
public void Paint( ElementId elementId, Face face, ElementId materialId ) |
Visual Basic |
---|
Public Sub Paint ( _ elementId As ElementId, _ face As Face, _ materialId As ElementId _ ) |
Visual C++ |
---|
public: void Paint( ElementId^ elementId, Face^ face, ElementId^ materialId ) |
Parameters
- elementId
- Type: Autodesk.Revit.DB..::..ElementId
The element that the face belongs to.
- face
- Type: Autodesk.Revit.DB..::..Face
The painted element's face.
- materialId
- Type: Autodesk.Revit.DB..::..ElementId
The material to be painted on the face
Examples
CopyC#
// Paint any unpainted faces of a given wall public void PaintWallFaces(Wall wall, ElementId matId) { Document doc = wall.Document; GeometryElement geometryElement = wall.get_Geometry(new Options()); foreach (GeometryObject geometryObject in geometryElement) { if (geometryObject is Solid) { Solid solid = geometryObject as Solid; foreach (Face face in solid.Faces) { if (doc.IsPainted(wall.Id, face) == false) { doc.Paint(wall.Id, face, matId); } } } } }
CopyC#
public void ApplyPaintByMaterial(Document document, Wall wall, Material material) { // Before acquiring the geometry, make sure the detail level is set to 'Fine' Options geoOptions = new Options(); geoOptions.DetailLevel = ViewDetailLevel.Fine; // Obtain geometry for the given Wall element GeometryElement geoElem = wall.get_Geometry(geoOptions); // Find a face on the wall Face wallFace = null; IEnumerator<GeometryObject> geoObjectItor = geoElem.GetEnumerator(); while (geoObjectItor.MoveNext()) { // need to find a solid first Solid theSolid = geoObjectItor.Current as Solid; if (null != theSolid) { // Examine faces of the solid to find one with at least // one region. Then take the geometric face of that region. foreach (Face face in theSolid.Faces) { if (face.HasRegions) { wallFace = face.GetRegions()[0]; break; } } } } if (null == wallFace) { TaskDialog.Show("Failure", "Could not find a face to paint on the given wall."); return; } // Paint material to the wall face (modification must be inside a transaction) using (Transaction transaction = new Transaction(document, "Painting a wall")) { transaction.Start(); document.Paint(wall.Id, wallFace, material.Id); transaction.Commit(); } // For illustration purposes only, check if the painted material indeed got applied bool isPainted = document.IsPainted(wall.Id, wallFace); if (isPainted) { ElementId paintedMatId = document.GetPaintedMaterial(wall.Id, wallFace); if (paintedMatId == material.Id) { TaskDialog.Show("Painting material", "Wall painted successfully."); } } }
CopyVB.NET
' Paint any unpainted faces of a given wall Public Sub PaintWallFaces(wall As Wall, matId As ElementId) Dim doc As Document = wall.Document Dim geometryElement As GeometryElement = wall.Geometry(New Options()) For Each geometryObject As GeometryObject In geometryElement If TypeOf geometryObject Is Solid Then Dim solid As Solid = TryCast(geometryObject, Solid) For Each face As Face In solid.Faces If doc.IsPainted(wall.Id, face) = False Then doc.Paint(wall.Id, face, matId) End If Next End If Next End Sub
CopyVB.NET
Public Sub ApplyPaintByMaterial(document As Document, wall As Wall, material As Material) ' Before acquiring the geometry, make sure the detail level is set to 'Fine' Dim geoOptions As New Options() geoOptions.DetailLevel = ViewDetailLevel.Fine ' Obtain geometry for the given Wall element Dim geoElem As GeometryElement = wall.Geometry(geoOptions) ' Find a face on the wall Dim wallFace As Face = Nothing Dim geoObjectItor As IEnumerator(Of GeometryObject) = geoElem.GetEnumerator() While geoObjectItor.MoveNext() ' need to find a solid first Dim theSolid As Solid = TryCast(geoObjectItor.Current, Solid) If theSolid IsNot Nothing Then ' Examine faces of the solid to find one with at least ' one region. Then take the geometric face of that region. For Each face As Face In theSolid.Faces If face.HasRegions Then wallFace = face.GetRegions()(0) Exit For End If Next End If End While If wallFace Is Nothing Then TaskDialog.Show("Failure", "Could not find a face to paint on the given wall.") Return End If ' Paint material to the wall face (modification must be inside a transaction) Using transaction As New Transaction(document, "Painting a wall") transaction.Start() document.Paint(wall.Id, wallFace, material.Id) transaction.Commit() End Using ' For illustration purposes only, check if the painted material indeed got applied Dim isPainted As Boolean = document.IsPainted(wall.Id, wallFace) If isPainted Then Dim paintedMatId As ElementId = document.GetPaintedMaterial(wall.Id, wallFace) If paintedMatId = material.Id Then TaskDialog.Show("Painting material", "Wall painted successfully.") End If End If End Sub
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions..::..ArgumentException | The element elementId does not exist in the document -or- The element materialId does not exist in the document -or- The face doesn't belong to the element -or- The materialId doesn't specify a material element. -or- The element's face cannot be painted. |
Autodesk.Revit.Exceptions..::..ArgumentNullException | A non-optional argument was null |
Autodesk.Revit.Exceptions..::..ModificationForbiddenException | The document is in failure mode: an operation has failed, and Revit requires the user to either cancel the operation or fix the problem (usually by deleting certain elements). -or- The document is being loaded, or is in the midst of another sensitive process. |
Autodesk.Revit.Exceptions..::..ModificationOutsideTransactionException | The document has no open transaction. |