Hi all,
See the below script from attached snip( My results right now all faces of wall )
I want a Python script for paint material face from wall, out put results should be only painted face with wall.
As a newcomers in Python language I can’t find out the solution, need assist.
Thank You
Hi,
I see you already have the Faces. The Face Class in The Revit API has a MaterialId property. I think this will return the paint material for that specific face.
I know that but i can’t understand, how to get MaterialId Property.
I see why you dont get the materiaId of the faces. This is because you are working with Dynamo Faces and not Revit API Faces. When you want to get access to the API properties of an object in Python you have to Unwrap that element. From that I wrote a method which gets the Geometry of the Element (In your case the walls) and I use that to get the Faces. When you have the Revit API Faces, you can get their MaterialId. If they are painted, it will give you the paint material, if they are not painted you will get the core material. (Code below)
import clr
#Import the Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
#Import the Revit Nodes
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#Import the Revit API
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
def tolist(obj1):
if hasattr(obj1,"__iter__"):
return obj1
else:
return [obj1]
def ReturnSingleOrList(list):
if len(list)==1:
return list[0]
else:
return list
#This returns all the Geometries in an element
def GetElementGeometries(element):
element = UnwrapElement(element)
result = []
geometries = element.Geometry[Options()]
for geometry in geometries:
result.append(geometry)
return ReturnSingleOrList(result)
#Define Input (IN)
walls = UnwrapElement(tolist(IN[0]))
output = []
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
options = Options()
for wall in walls:
wallMaterials = []
wallGeometry = GetElementGeometries(wall)
wallFaces = wallGeometry.Faces
for face in wallFaces:
materialId = face.MaterialElementId
material = doc.GetElement(materialId)
wallMaterials.append(material)
output.append(wallMaterials)
#End Transaction
TransactionManager.Instance.TransactionTaskDone()
#Define Output (OUT)
OUT = output
2 Likes