[英]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. 我试图在Revit 2014中用宏绘制墙。首先获取材料,然后获取墙的面,但是当我选择墙时,什么也没有发生。 This is the code in Python: 这是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)
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.