I discovered i lack of some basic knowledge.
I used the template of “simple operator” to do a test.
The operator “starts” passing to the main function the context.
def execute(self, context):
main(context)
So from “main” i can just type context.selected_objects
Without the bpy. to get the list, and do stuff.
def testShow(self):
main2(self)
But even if the context is not passed, like this,
i can still get that list from main2 writing the whole address
print ( len( bpy.context.selected_objects ) )
I used a lot the template of the raycast,
That template works using a “modal” that pass the Event,
so from that template i can easily access the mouse_x.
Today for Learning and practice ,
i decided to try to turn that “Modal-template”
into a simple operator, and i am fallen into oblivion.
my questions:
How i get the mouse x ? in the View_3d ?
Can i convert that template in a simple-operator ?
No because the mouse_x is only avaible in event & modal?
The Event passed in that template , from where came from?
Why is not accessible like " bpy.types.Event.mouse_region_x "
Making my own operator and functions how should i think about these “context”
This is a beginner question, but how is named this?
What should i search for understand this ?
Here my playcode- with the commented line
import bpy
print( "-------------------------------")
print( "-------------------------------")
print( "Direct access bpy.context " + str( bpy.context.screen.areas[1].type ) )
#print( bpy.types.Event.mouse_region_x ) ### type object 'Event' has no attribute 'mouse_region_x'
def main(context):
print( "Number of object selected " + str( len( bpy.context.selected_objects ) ) )
print( "-----ALL_AREA_INFO -------------")
for area in context.screen.areas:
print (
str (context.region.height) + " " +
str (context.region.type) +
" " + str (area.type) +
" W " + str( area.width) +
" H " + str( area.height)
)
for area in bpy.context.screen.areas:
if area.type == "VIEW_3D" :
print( "---- VIEW_3D ROT_LOC_MATRIX -------------")
# print( area.spaces.active.region_3d.view_matrix )
# print( area.spaces[0].region_3d.view_rotation)
# print( area.spaces[0].region_3d.view_location)
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator123"
bl_label = "123 Simple Object Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.simple_operator123()