我目前正在通过 pyRevit 开发一个 Revit 插件,我在从 Python 中定义的三个顶点开始创建一个新的 Revit 三角形地板时遇到了一些麻烦。我是 Revit API 的新手,目前正在使用 Revit 2023。
我知道 API 相对于以前的版本有一些变化,例如新的 Floor.Create() 方法。但是,当我运行我的代码时,我收到错误消息“ArgumentException:输入曲线循环无法构成有效边界,这意味着:“curveLoops”集合为空;或者一些曲线循环相互交叉;或者每条曲线环未单独闭合;或每个曲线环都不是平面的;或每个曲线环不在平行于水平 (XY) 平面的平面内;或输入曲线至少包含一条螺旋曲线。参数名称:Autodesk.Revit 中的配置文件.DB.Floor.Create(Document document, IList`1 profile, ElementId floorTypeId, ElementId levelId).
经过进一步检查,我检查了 CurveLoop() 并且一切似乎都井井有条(它是平面的、闭合的和逆时针方向的)。我将不胜感激解决此问题的任何帮助。
#! python3
#----------------------------------------------------------------------------------------------
# IMPORT LIBRARIES
# System library
import sys
# Autodesk Revit API
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import Transaction
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import XYZ, UV, Line, CurveLoop, Level, Floor, FloorType
from System.Collections.Generic import List
# Function to convert centimeters to feet
def centimeters_to_feet(centimeters):
return centimeters * 0.0328084
doc = __revit__.ActiveUIDocument.Document
# Coordinates
a = 0.0
b = 10.0
c = 0.0
# Input elevation (in centimeters)
elevation_cm = c
elevation_ft = centimeters_to_feet(elevation_cm)
# Create a new level at the given elevation
new_level = None
# Start a new transaction to modify the Revit document creating a new level
transaction = Transaction(doc, 'Create New Level')
transaction.Start()
try:
new_level = Level.Create(doc, elevation_ft)
# Assign a new name to the level
new_level_name = "elBS_BuildingStorey_{:.0f}cm".format(elevation_cm)
new_level.Name = new_level_name
transaction.Commit()
except Exception as e:
# If an error occurs, roll back the transaction and show an error message
transaction.RollBack()
TaskDialog.Show('Error', 'Failed to create level. Error: {}'.format(e))
if new_level:
TaskDialog.Show('Success', 'Level created at elevation: {} centimeters'.format(elevation_cm))
# Create new floor
point0 = XYZ(a, a, c)
point1 = XYZ(b, a, c)
point2 = XYZ(b, b, c)
line01 = Line.CreateBound(point0,point1).ToRevitType()
line12= Line.CreateBound(point1,point2).ToRevitType()
line23 = Line.CreateBound(point2,point0).ToRevitType()
curveloop = CurveLoop()
curveloop.Append(line01)
curveloop.Append(line12)
curveloop.Append(line23)
print("numberOfcurves: ",curveloop.NumberOfCurves())
print("IsOpen: ",curveloop.IsOpen())
print("HasPlane: ",curveloop.HasPlane())
# Collect floor types
floortypes = FilteredElementCollector(doc).OfClass(FloorType)
floortypes = [f for f in floortypes]
floortypes_id = [f.Id for f in floortypes]
floortype_id = floortypes_id[0]
print("floortype id:",floortype_id)
# Collect building storeys
el_BuildingStoreys = FilteredElementCollector(doc).OfClass(Level)
el_BuildingStoreys_id = []
for el in el_BuildingStoreys:
el_BuildingStoreys_id.append(el.Id)
level_id = el_BuildingStoreys_id[0]
print("level id: ",level_id)
# Start transaction
t = Transaction(doc, "Create new floor")
t.Start()
# Create the floor
new_floor = Floor.Create(doc, List[CurveLoop](curveloop), floortype_id, new_level.Id)
t.Commit()