0

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?

DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
  • You can use `print` statements to help debugging. Or try it out in the shell, line by line. Is the `geomObject` ever a `Solid`? You should find that out - it would explain very easily why you're not getting any result. – Daren Thomas Nov 30 '15 at 08:59
  • Daren, Thanks for your tips, are very useful. – CADesigner Dec 01 '15 at 16:29

1 Answers1

1

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)

}

Rolando
  • 11
  • 1