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?
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.
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
'VIEW_3D'
>>> C.screen.areas[4].spaces[0].region_
3d
quadview
>>> C.screen.areas[4].spaces[0].region_