Revit API |如何画墙?

时间:2015-11-28 21:56:03

标签: python revit-api revit

我正在尝试在Revit 2014中绘制带有宏的墙。首先我得到了材料然后是墙的面,但是当我选择墙时没有任何反应。这是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)

有谁可以帮我弄清楚为什么会这样?

1 个答案:

答案 0 :(得分:0)

您必须启动交易才能对模型进行更改。

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)

}