diff --git a/old.py b/new.py index c54270a..c9ac664 100644 --- a/old.py +++ b/new.py @@ -46,13 +46,11 @@ def load_library(dummy): for workspace in bpy.data.workspaces: workspace.asset_library_ref = LIBRARY_NAME -def get_selection_point(context, event): +def get_selection_point(context, region, event): """Run this function on left mouse, execute the ray cast""" # get the context arguments scene = context.scene - region = context.region - #NO 3D VIEW REGION DATA FOUND??? - rv3d = context.region_data + rv3d = region.data coord = event.mouse_region_x, event.mouse_region_y # get the ray from the viewport and mouse @@ -135,10 +133,21 @@ class test_library_OT_place_object(bpy.types.Operator): self.obj = obj context.view_layer.active_layer_collection.collection.objects.link(obj) + @staticmethod + def get_main_region(context): + for region in context.area.regions: + if region.type == 'WINDOW': + return region + return None + def modal(self, context, event): context.view_layer.update() - selected_point, selected_obj, selected_normal = get_selection_point(context,event) + region = self.get_main_region(context) + if not region: + return {'RUNNING_MODAL'} + + selected_point, selected_obj, selected_normal = get_selection_point(context,region,event) self.obj.location = selected_point if event.type == 'LEFTMOUSE' and event.value == 'PRESS':