从折线获取曲线以创建详图线

时间:2019-06-04 12:53:26

标签: python ironpython revit-api revitpythonshell

我正在尝试创建一个可以根据选择内容创建明细行的脚本。

尽管每行的行长都在5'左右,但脚本会显示以下错误:

  

Exception:Autodesk.Revit.Exceptions.ArgumentsInconsistentException:曲线长度对于Revit的公差而言太小(由Application.ShortCurveTolerance标识)   参数名称:端点

我的代码是:

#Import Autodesk stuffs
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI.Selection import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

# Import iron python packages
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager


app = __revit__.Application
Ui = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
view = doc.ActiveView

#TransactionManager.Instance.ForceCloseTransaction()
#t = Transaction(doc, "Create CAD Copy")  
#t.Start()

from Autodesk.Revit.UI import Selection


selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
curve = []
opt = Options()

allGeom =[]
solidGeoms=[]
for i in selection:
    geo = i.get_Geometry(opt)
    for a in geo:
        geo = a.GetInstanceGeometry()
        for g in geo:
            allGeom.append(g)

Lines=filter(lambda x : type(x)==Line,allGeom)

polylines1=filter(lambda x : type(x)==PolyLine,allGeom)
polylines2=filter(lambda x : type(x)==PolyLine,allGeom)

polypoints1=[]

for i in polylines1:
    a = i.GetCoordinates()
    polypoints1.Add(a)


pointlist1=[]
for i in polypoints1:
    j=i
    i.RemoveAt(0)
    pointlist1.append(i)
print(pointlist1)


polypoints2=[]

for i in polylines2:
    a = i.GetCoordinates()
    polypoints2.Add(a)


pointlist2=[]
for i in polypoints2:
    j=i
    m=i.Count
    i.RemoveAt((m-1))
    pointlist2.append(i)
print(pointlist2)

line=[]
for i in pointlist1:
    for j in pointlist2:
        for a in i: 
            for b in j:
                line.append(Line.CreateBound(a,b))

1 个答案:

答案 0 :(得分:0)

您四个嵌套的for循环将产生大量行。我无法想象您真的需要所有这些。您可以添加一个断言,以保证ab之间的最小距离始终大于,例如,大约十分之一英寸。 2.5毫米我打赌断言会触发。换句话说,您的某些行可能短于5'。也许有些甚至是零长度?