Revit API python错误:异常:idx只能是0,1,2

问题描述 投票:0回答:2

有人可以帮助我理解这个错误。我还在学习Revit API(和python)并且搜索没有帮助。我正在尝试获取元素的xyz位置点。

这是我的代码:

elements= ui.Selection() 
for d in elements:
for l in d.Parameters:
    for x in d.Location.Point:
        print x

这是输出,注意:它确实返回三个值:

149.412934765
69.7704247908
-3.71628688979

这是错误消息。我不明白错误消息中对idx的引用:

IronPython Traceback:
Traceback (most recent call last):
 File "C\BTS-NY-BETA.extension\BTS-NY-BETA.tab\Beta Tools.panel\BETA3.pushbutton\Get linked docs_script.py", line 32, in 
Exception: idx can be only 0, 1, 2.
Parameter name: idx


Script Executor Traceback:
Autodesk.Revit.Exceptions.ArgumentOutOfRangeException: idx can be only 0, 1, 2.
Parameter name: idx

 at Autodesk.Revit.DB.XYZ.get_Item(Int32 idx)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at IronPython.Runtime.ItemEnumerator.System.Collections.IEnumerator.MoveNext()
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitBaseClasses.ScriptExecutor.ExecuteScript(PyRevitCommandRuntime& pyrvtCmd)
revit-api pyrevit
2个回答
2
投票

Point不是值数组,访问X,Y,Z是正确的方法。


0
投票

虽然我仍然不理解错误,但我能够通过编辑我的代码来消除错误消息,如下所示:

elements= ui.Selection() 
for d in elements:
for l in d.Parameters:
    for pt in d.Location.Point:
        print pt.X
        print pt.Y
        print pt.Z
© www.soinside.com 2019 - 2024. All rights reserved.