简体   繁体   中英

Revit API | How to paint a wall?

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?

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)

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM