0

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
Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125

1 Answers1

2

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]
uvnoob
  • 436
  • 2
  • 8