Reputation: 1
I'm trying to paint a wall with macros in Revit 2014. First I get the material and then the faces of the wall, but when I select the wall nothing happens. This is the code in Python:
def PaintFace(self):
uidoc = self.ActiveUIDocument
doc = uidoc.Document
collector = FilteredElementCollector(doc)
materials = collector.WherePasses(ElementClassFilter(Material)).ToElements()
for material in materials:
if material.Name == 'Copper':
matName = material
break
elRef = uidoc.Selection.PickObject(ObjectType.Element)
wall = doc.GetElement(elRef)
geomElement = wall.get_Geometry(Options())
for geomObject in geomElement:
if geomObject == Solid:
solid = geomObject
for face in solid.Faces:
if doc.IsPainted(wall.Id, face) == False:
doc.Paint(wall.Id, face, matName.Id)
Could anyone help me figure out why is this happening?
Upvotes: 0
Views: 728
Reputation: 11
You have to start a Transaction to make a change in the model.
public void PaintFace(self):
uidoc = self.ActiveUIDocument
doc = uidoc.Document
using(Transaction tr = new Transaction (doc,"PaintWall")
{
collector = FilteredElementCollector(doc)
materials = collector.WherePasses(ElementClassFilter(Material)).ToElements()
for material in materials:
if material.Name == 'Copper':
matName = material
break
elRef = uidoc.Selection.PickObject(ObjectType.Element)
wall = doc.GetElement(elRef)
geomElement = wall.get_Geometry(Options())
for geomObject in geomElement:
if geomObject == Solid:
solid = geomObject
for face in solid.Faces:
if doc.IsPainted(wall.Id, face) == False:
doc.Paint(wall.Id, face, matName.Id)
}
Upvotes: 1