System console tells me "convertViewVec: called in an invalid context"

I’m using the “copy paste” command moving my object to (1, 1, 0). Blender tells me this should read:

bpy.ops.transform.translate(value=(0, 0, 0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(1, 1, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)

It works like it should, but i get this message. In what way am I calling this in “an invalid context”?
Alternatively: Can I just stop the message from displaying in the system console?

Hi Ruff,

if you know where you are moving your object to


import bpy

context = bpy.context
obj = context.active_object 
obj.location = (1, 0, 0)  # accepts tupples,  use Vector if you are going to do calcs.


Similarly if you want to translate, ie move (1, 1, 0) from where it was



import bpy
from mathutils import Vector

context = bpy.context
obj = context.active_object

obj.location += Vector([1, 1, 0])


You are getting the error because the translate op uses the view. The op you posted has a translation of (0, 0, 0) so it may have appeared to have worked… how would you tell?

Oh, sorry. The code i posted should have had value=(1,1,0) (and snap_point=(0,0,0)). I rewrote that manually just to have some example.

Your solution worked. Thanks!
What does it mean; using translate from view?

operators require a certain context, which means mouse cursor has to be in certain area/region, for example, transform operators require the 3d view, they can’t work in file browser.

@batFinger: i should rather be
obj.location += Vector((1,0,0)) # tuple, not list!

([]) looks ugly :wink:

Hi have same error message:

From an addon:

def step6():
print(“step6 de vertices voor extrude kiezen en extruden”, bpy.context.area.type)

#PKHG>???? bpy.context.active_object.name = "Gus"
#PKHG>CRASH!!!! bpy.context.area.type = "VIEW_3D"
selectVertices([2,7,3,8,13,5])
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False}, TRANSFORM_OT_translate={"value":(1.5, 0, 0)})
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False}, TRANSFORM_OT_translate={"value":(0.5, 0, 0)})
#PKHG>???? 
#bpy.context.area.type="PROPERTIES"

My try to set the context lets Blender 2.70a crash ;-( …

Can the warning(more is it not) be suppressed (making Blender happy) ?

As far as I know, you shouldn’t set the context. Rather, you can copy the context, change the copy and then give it as an argument to the operator as an override context. I don’t have example code here as I only have my tablet at hand, sorry. Just google override context blender python, or something similar.

Thanks for trying … BUT… context changing is WEL done at other steps of my application (building a mesh)
Even needed! E.g. I have a button in PROPERTIES part of the screen to activate a step, and somtimes (without changing context)
the PROPERTIES became VIEW_3D context, so a step sets it back to PROPERTIES … and it works as meant ;-).

I just do not understand : convertViewVec called in an invalid context
What is wrong and how to give it the RIGHT context and evt. again back to PROPERTIES???

I don’t get understand how you can be in the wrong context and only get a warning. Maybe you should make a new thread that has not been marked solved, as to attract attention from people wiser than me, like CoDEmanX.

OK will do so … with even more explanations …did not realize the SOLVED mark, thanks PhysicsGuy ;-).

Got my stepwise script more or less working again for Blender 2.76b :wink:

But that strange error occurs nevertheless and I do not understand here part of what I printed to the console:
step20 create een oog, op goede plaats en iets plat
step20 bpy.context.active_object.name= Sphere
step20 bpy.context.active_object.name= Gus_ogen
dupliceer oog en zet de kleur
step21-0 bpy.context.active_object.name= Gus_ogen
convertViewVec: called in an invalid context
step21-1 bpy.context.active_object.name= Gus_ogen
step21-2 bpy.context.active_object.name= Gus_ogen
step22 create de mond, op goede plaats en iets plat

and here thos two def’s

 
def step21():
    print("dupliceer oog en zet de kleur")
    print("step21-0 bpy.context.active_object.name= ", bpy.context.active_object.name)
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.duplicate_move(MESH_OT_duplicate={"mode":1}, TRANSFORM_OT_translate={"value":(-.9, 0, 0)})
    print("step21-1 bpy.context.active_object.name= ", bpy.context.active_object.name)
    bpy.ops.object.editmode_toggle()
    print("step21-2 bpy.context.active_object.name= ", bpy.context.active_object.name)
    donkerbruin = makeMaterial("darkbrown", (0.115, 0.0418, 0.0), (1, 1, 1), 1)
    ogen = bpy.data.objects['Gus_ogen']
    setMaterial(ogen,donkerbruin)

def step22():
    print("step22 create de mond, op goede plaats en iets plat ")
    bpy.ops.mesh.primitive_uv_sphere_add(segments=16, ring_count=16, size=.1,
     view_align=False, enter_editmode=False, location=(0.3, -.15, 1.3))
    bpy.context.active_object.name = "Gus_mond"
    bpy.ops.transform.resize(value=(1, 0.5, 1))
    bpy.ops.object.mode_set(mode='EDIT')


Hope that someone understands and could tell me to not being in WRONG context :wink:

PKHG, as I alluded to in a previous answer, I believe the
bpy.ops.mesh.duplicate_move

operator uses the matrix of the 3d view to translate, and the error is due to it being run instead from the text editor
I tried wrapping with a change of area, or changing area and context members of context.copy() but unfortunately it crashes my blender.

Thanks, it begins to be clearer, a reason why … will see what I will come across

Thanks again …