【问题标题】:Revit API | How to paint a wall?Revit API |如何粉刷墙壁?
【发布时间】:2016-02-05 05:26:39
【问题描述】:

我正在尝试在 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)

谁能帮我弄清楚为什么会这样?

【问题讨论】:

  • 您可以使用print 语句来帮助调试。或者在 shell 中逐行尝试。 geomObject 曾经是 Solid 吗?你应该发现这一点 - 它会很容易地解释为什么你没有得到任何结果。
  • 达人,谢谢你的提示,很有用。

标签: python revit-api revit


【解决方案1】:

您必须启动一个事务才能对模型进行更改。

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)

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 2013-05-11
    • 2014-03-23
    • 2019-03-08
    • 2021-07-15
    • 2018-12-17
    • 2020-04-20
    相关资源
    最近更新 更多