# Problem executing string

In 2.79 I was using exec() with a string to run operators, however in 2.8 copying from the info panel into exec() gives an error with the constraint_matrix:

exec("bpy.ops.transform.translate(value=(29.2064, -10.7433, 26.947), constraint_matrix=(1, 0, 0, 0, 1, 0, 0, 0, 1))")


Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "<string>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender 2-8\2.80\scripts\modules\bpy\ops.py", line 200, in __call__
ret = op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  expected a sequence of float, not int


Is there any way to be able to exec() from a string copied straight from the info panel?

Seems it's not a issue with the way you're doing it. It also throws a error if you run it like this.

import bpy

bpy.ops.transform.translate(value=(29.2064, -10.7433, 26.947), constraint_matrix=(1, 0, 0, 0, 1, 0, 0, 0, 1))


or if you changed the numbers like this.

import bpy

bpy.ops.transform.translate(value=(29.2064, -10.7433, 26.947), constraint_matrix=(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))


I reported as bug ,but it got closed. If you look at docs you can do something like this. https://docs.blender.org/api/blender2.8/bpy.ops.transform.html#bpy.ops.transform.translate

import bpy

exec("bpy.ops.transform.translate(value=(29.2064, -10.7433, 26.947), constraint_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)))")


Looks like it doesn't get everything printed in Info window and causes the error.

• Ergh, I'm going to have to check each string and replace it with a tuple. Thank you so much though. – Way2Close Feb 14 '19 at 19:18

I added a bug report at:
https://developer.blender.org/T61563 which got accepted, but out of personal learning this takes the string and converts it to a sequence of floats. Additional information at Converting string int-tuple to float-tuple

import bpy
import re
from ast import literal_eval

test_text = "bpy.ops.transform.translate(value=(-0.1, 0.1, 0.1), constraint_matrix=(1, 0, 0, 0, 1, 0, 0, 0, 1)"

if "constraint_matrix" in test_text:

string_out = str((test_text.split('constraint_matrix=('))[1].split(')')[0])

try:
string_out = literal_eval(string_out)

string_out = tuple(zip(*(string_out[i::3] for i in range(3))))

test_text = re.sub('constraint_matrix=$$[^)]+$$',"constraint_matrix=" + str(string_out), test_text)
except SyntaxError:
pass

print(test_text)


prints:
bpy.ops.transform.translate(value=(-0.1, 0.1, 0.1), constraint_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1))