【问题标题】:Revit API InvalidOperationException: Invalid number of references. IronpythonRevit API InvalidOperationException:引用数无效。铁蟒
【发布时间】:2021-02-25 01:50:53
【问题描述】:

在这段代码中,我试图通过边界线创建一个新维度作为参考,但它抛出了 InvalidOperationException: Invalid number of references。我想为边界的每一行添加一个新维度。

谁能帮帮我?

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Transaction, Plane
from Autodesk.Revit.UI import Selection

doc=__revit__.ActiveUIDocument.Document
uidoc=__revit__.ActiveUIDocument

filledregion_ids=uidoc.Selection.GetElementIds()
filledregion_elements=[]
for id in filledregion_ids:
    filledregion_elements.append(doc.GetElement(id))

curve_ref_even=ReferenceArray()
curve_ref_odd=ReferenceArray()
count=0
boundcount=0
regcount=0

newplane=Plane.CreateByThreePoints(XYZ(100,0,0),XYZ(0,100,0),XYZ(0,0,0))
'''Getting filled regions'''
for region in filledregion_elements:
    boundary=region.GetBoundaries()
    for bound in boundary:
        boundcount+=1
        print(boundcount)  
        lastline=list(bound)[0]
        for lines in bound:
            if (count//2)==0:
             curve_ref_even.Append(lines.Reference)
             print(curve_ref_even)
             if len(list(curve_ref_even))==2:
              t= Transaction(doc, "Create dimension")
              t.Start()
              doc.Create.NewDimension(doc.ActiveView,lines,curve_ref_even)
              t.Commit()
             count+=1
            else:
             curve_ref_odd.Append(lines.Reference)
             print(curve_ref_odd)
             if len(list(curve_ref_odd))==2:
              t= Transaction(doc, "Create dimension")
              t.Start()
              doc.Create.NewDimension(doc.ActiveView,lines,curve_ref_odd)
              t.Commit()
              count+=1

    boundcount=0
    count=0

【问题讨论】:

    标签: ironpython revit-api


    【解决方案1】:

    我建议至少将您的代码分成两个独立的部分。一部分用于处理从边界列表中选择参考点并确保您将正确的对放在一起的逻辑,另一部分用于实际创建尺寸。你在上面做的事情对我的口味来说太聪明了,而且不值得信赖。我不确定您是否可以在GetBoundaries 返回的边界段列表中假设任何特定顺序。顺便说一句,The Building Coder 在creating dimensioning 上提供了完整的文章列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      • 2020-04-20
      • 1970-01-01
      • 2017-01-14
      • 2012-05-18
      • 2016-10-24
      相关资源
      最近更新 更多