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$

1 Answer 1

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$
    – pleaseh3lp
    Commented Aug 22, 2020 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .