Context problem

Hi, i’ ve a problem with this function:


when i lunch the script it report this error

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'SpaceConsole' object has no attribute 'region_3d'

i tried to use the if function with the LEFTMOUSE so when i click in 3d viewport the function start but dont’ work, so i can make this function work?

p.s: i’m in modal mode

1 Like

You are running it from the console where context.space_data.type will be “CONSOLE”. Which doesn’t have a region_3d attribute. Run it from a VIEW_3D space.

the problem is this! how i can run it in view 3d?? since i run it in the script editor i don’t know how to do this!

Make it an operator. Execute / Invoke that operator via a button in the 3dview properties or using the space bar search for op menu in that space… or a menu in that space
You can also swap the area type in your script, but since you are talking modal op / mouse events use one of the above.

Otherwise if you are calling it from the console you can find the space_data via

>>> C.screen.areas[4].type

>>> C.screen.areas[4].spaces[0].region_
>>> C.screen.areas[4].spaces[0].region_

The indexes may differ for your set up.

1 Like

ok, i’ve just created a button option in the mesh menu! thanks for the tip!!