DocumentPaint(ElementId, Face, ElementId) Method |
Paint the element's face with specified material.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntaxpublic void Paint(
ElementId elementId,
Face face,
ElementId materialId
)
Public Sub Paint (
elementId As ElementId,
face As Face,
materialId As ElementId
)
public:
void Paint(
ElementId^ elementId,
Face^ face,
ElementId^ materialId
)
member Paint :
elementId : ElementId *
face : Face *
materialId : ElementId -> unit
Parameters
- elementId ElementId
-
The element that the face belongs to.
- face Face
-
The painted element's face.
- materialId ElementId
-
The material to be painted on the face
ExceptionsException | Condition |
---|
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.
|
ArgumentNullException |
A non-optional argument was null
|
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.
|
ModificationOutsideTransactionException |
The document has no open transaction.
|
Example
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);
}
}
}
}
}
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
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
public void ApplyPaintByMaterial(Document document, Wall wall, Material material)
{
Options geoOptions = new Options();
geoOptions.DetailLevel = ViewDetailLevel.Fine;
GeometryElement geoElem = wall.get_Geometry(geoOptions);
Face wallFace = null;
IEnumerator<GeometryObject> geoObjectItor = geoElem.GetEnumerator();
while (geoObjectItor.MoveNext())
{
Solid theSolid = geoObjectItor.Current as Solid;
if (null != theSolid)
{
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;
}
using (Transaction transaction = new Transaction(document, "Painting a wall"))
{
transaction.Start();
document.Paint(wall.Id, wallFace, material.Id);
transaction.Commit();
}
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.");
}
}
}
Public Sub ApplyPaintByMaterial(document As Document, wall As Wall, material As Material)
Dim geoOptions As New Options()
geoOptions.DetailLevel = ViewDetailLevel.Fine
Dim geoElem As GeometryElement = wall.Geometry(geoOptions)
Dim wallFace As Face = Nothing
Dim geoObjectItor As IEnumerator(Of GeometryObject) = geoElem.GetEnumerator()
While geoObjectItor.MoveNext()
Dim theSolid As Solid = TryCast(geoObjectItor.Current, Solid)
If theSolid IsNot Nothing Then
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
Using transaction As New Transaction(document, "Painting a wall")
transaction.Start()
document.Paint(wall.Id, wallFace, material.Id)
transaction.Commit()
End Using
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
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also