我正在尝试使用RevitPythonshell覆盖Revit中3D视图中的墙的图形。我设法使用Python节点在Dynamo中完成这项工作。
到目前为止,我有以下代码;
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import List
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
elements = walls.OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()
color = Autodesk.Revit.DB.Color(255,50,50)
ogs = OverrideGraphicSettings().SetProjectionFillColor(color)
for i in elements:
doc.ActiveView.SetElementOverrides((i.Id), ogs)
TransactionManager.Instance.TransactionTaskDone()
当我在RevitPythonShell中运行它时,它什么也没做。我没有任何错误或任何错误。当我打印doc.ActiveView.SetElementOverrides((i.Id), ogs)
时,它返回None。
我在这里缺少什么?我在Revit中的3D视图中是活动视图。我正在开始并结束交易。
Here与Dynamo节点中的Python节点中的代码有些相同。
答案 0 :(得分:1)
通过一些调整,您的代码可以正常运行:
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
elements = list(FilteredElementCollector(doc, doc.ActiveView.Id))
color = Color(255,50,50)
ogs = OverrideGraphicSettings().SetProjectionFillColor(color)
t = Transaction(doc, 'Color Walls')
t.Start()
try:
for i in elements:
if i.Category.Name == 'Walls':
doc.ActiveView.SetElementOverrides((i.Id), ogs)
print 'element overridden'
except Exception as e:
print '- Failed to override -'
print '- ' + str(e) + ' -'
t.Commit()
View.Id
传递给FilteredElementCollector
时,您会收集
在该视图中可见的一切答案 1 :(得分:1)
我设法以下列方式为不同类型的墙壁着色。
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
from random import randint
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
#elements = list(FilteredElementCollector(doc, doc.ActiveView.Id))
wall_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
wall_instances = wall_collector.OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()
fill_patterns = FilteredElementCollector(doc).OfClass(FillPatternElement).WhereElementIsNotElementType().ToElements()
for i in fill_patterns:
if i.Name == 'Solid fill':
solid_fill = i.Id
element_list = []
element_name_list = []
for i in wall_instances:
element_name_list.append(i.Name)
element_list.append(i.Id)
wall_color_dict = {}
for i in set(element_name_list):
wall_color_dict[i] = Color(randint(0,250), randint(0,250), randint(0,250))
t = Transaction(doc, 'Color Walls')
t.Start()
for i in wall_instances:
for k, v in wall_color_dict.iteritems():
if k == i.Name:
a=OverrideGraphicSettings().SetProjectionFillPatternId(solid_fill)
b=OverrideGraphicSettings(a).SetProjectionFillColor(v)
p = doc.ActiveView.SetElementOverrides(i.Id, a)
c = doc.ActiveView.SetElementOverrides(i.Id, b)
t.Commit()
运行脚本后: