// Paint any unpainted faces of a given wallpublicvoid 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);
}
}
}
}
}
publicvoid 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 appliedbool 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.");
}
}
}
' Paint any unpainted faces of a given wallPublicSub PaintWallFaces(wall As Wall, matId As ElementId)
Dim doc As Document = wall.Document
Dim geometryElement As GeometryElement = wall.Geometry(New Options())
ForEach geometryObject As GeometryObject In geometryElement
IfTypeOf geometryObject Is Solid ThenDim solid As Solid = TryCast(geometryObject, Solid)
ForEach face As Face In solid.Faces
If doc.IsPainted(wall.Id, face) = FalseThen
doc.Paint(wall.Id, face, matId)
EndIfNextEndIfNextEndSub
PublicSub 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 AsNew Options()
geoOptions.DetailLevel = ViewDetailLevel.Fine
' Obtain geometry for the given Wall elementDim geoElem As GeometryElement = wall.Geometry(geoOptions)
' Find a face on the wallDim wallFace As Face = NothingDim geoObjectItor As IEnumerator(Of GeometryObject) = geoElem.GetEnumerator()
While geoObjectItor.MoveNext()
' need to find a solid firstDim theSolid As Solid = TryCast(geoObjectItor.Current, Solid)
If theSolid IsNotNothingThen' Examine faces of the solid to find one with at least' one region. Then take the geometric face of that region.ForEach face As Face In theSolid.Faces
If face.HasRegions Then
wallFace = face.GetRegions()(0)
ExitForEndIfNextEndIfEndWhileIf wallFace IsNothingThen
TaskDialog.Show("Failure", "Could not find a face to paint on the given wall.")
ReturnEndIf' Paint material to the wall face (modification must be inside a transaction)Using transaction AsNew Transaction(document, "Painting a wall")
transaction.Start()
document.Paint(wall.Id, wallFace, material.Id)
transaction.Commit()
EndUsing' For illustration purposes only, check if the painted material indeed got appliedDim isPainted AsBoolean = document.IsPainted(wall.Id, wallFace)
If isPainted ThenDim paintedMatId As ElementId = document.GetPaintedMaterial(wall.Id, wallFace)
If paintedMatId = material.Id Then
TaskDialog.Show("Painting material", "Wall painted successfully.")
EndIfEndIfEndSub
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.
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.
Erik will look at it. You can keep using the site.
Embed this page
Sections to include
Theme
Adds a tiny script so the iframe grows to fit its content. Some sites (Medium, Notion) strip scripts, leave this off for those and the embed scrolls inside a fixed height.