0
$\begingroup$

I am trying to execute my command with two arguments in terminal:

blender -b Scripting_Testing.blend -P background_job.py -- 1 2

I have used:

import sys

try:
    index = sys.argv.index("--") + 1
except ValueError:
    index = len(sys.argv)
sys.argv = sys.argv[index:]
....
....
foot_position = sys.argv[1]
angle_movement = sys.argv[2]

(Used from Here)

I get:

IndexError: list index out of range
$\endgroup$
2
$\begingroup$

All the parameters before "--" (+ 1 makes it inclusive) have been skipped here. The second line overrides the sys.argv to hold only items that go after "--", which is an array of length 2 containing [1, 2].

index = sys.argv.index("--") + 1
sys.argv = sys.argv[index:]

Array indices start from 0. You are trying to access a third parameter here

angle_movement = sys.argv[2]

This causes the out of index exception. Should be

foot_position = sys.argv[0]
angle_movement = sys.argv[1]
$\endgroup$
1
  • $\begingroup$ Thank you for your help! $\endgroup$ Aug 22 '20 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.