Revit API python Ошибка: исключение: idx может быть только 0, 1, 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)

person user3808752    schedule 10.03.2019    source источник
comment
Что на 32 строке скрипта Get linked docs_script.py?   -  person Ehsan Iran-Nejad    schedule 11.03.2019


Ответы (2)


Point - это не массив значений, доступ к X, Y, Z - правильный.

person Matt    schedule 10.03.2019

Хотя я все еще не понимаю ошибку, мне удалось устранить сообщение об ошибке, отредактировав свой код следующим образом:

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
person user3808752    schedule 10.03.2019
comment
Во-первых, не гарантируется, что местоположение будет Point. Это также может быть Line, и в этом случае ваш код вызовет исключение. Кроме того, я хочу повторить комментарии Мэтта о том, что вам не нужно повторять Point. Чтобы получить значения XYZ, просто вызовите loc = d.Location.Point, а затем print loc.X и т. Д. Нет смысла перебирать такие свойства точки. - person konrad; 10.03.2019
comment
@Matt и Konrad - да, я вижу, что вы правы, без вопросов, интересно, что итерация по нему дала результаты, которые, как я думал, будут, а затем выдала ошибку - person user3808752; 10.03.2019
comment
пожалуйста, не забудьте принять ответ Мэтта. Его предложение здесь правильное. - person konrad; 11.03.2019