Skip to content

[NOT A BUG] Modal timing / watching inside Blender while running in VR #44

@ptabriz

Description

@ptabriz

Hello all,
I am very new to Github so and I am not sure if this is the right place to post a question. if this the case,please advise me where to post this,

I have written a script in blender using modal timer that constantly watches a folder to a import .ply and a Georaster as they get updated in GRASS GIS via Kinect. The code also watches for new GIS shapefiles that define a camera path or spot.

I am looking for a recommendations on how to use this blender file in BlenderVR. Can I load the blender file in VR and write the processor file as such that read and run the script inside the blender file ?

Below is part of the code inside blender.

pointPath= "C:/Users/ptabriz/Desktop/Blender_raster/Test_1/new.ply"
scratchPointPath= "C:/Users/ptabriz/Desktop/Blender_raster/Test_1/scratch.ply"

class ModalTimerOperator(bpy.types.Operator):
"""Operator which runs its self from a timer"""
bl_idname = "wm.modal_timer_operator"
bl_label = "Modal Timer Operator"

_timer = 2

def modal(self, context, event):
    if event.type in {'RIGHTMOUSE', 'ESC'}:
        self.cancel(context)
        return {'CANCELLED'}

    if event.type == 'TIMER':
        if os.path.exists(pointPath):

            #bpy.context.selected_objects
            bpy.ops.import_mesh.ply(filepath=pointPath,directory="C:/Users/ptabriz/Desktop/Blender_raster/",filter_glob="1.ply")
            os.rename(pointPath,scratchPointPath)
            bpy.data.objects["new"].select = True
            bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')
            bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')   
    return {'PASS_THROUGH'}

def execute(self, context):
    wm = context.window_manager
    self._timer = wm.event_timer_add(0.1, context.window)
    wm.modal_handler_add(self)
    return {'RUNNING_MODAL'}

def cancel(self, context):
    wm = context.window_manager
    wm.event_timer_remove(self._timer)

def register():
bpy.utils.register_class(ModalTimerOperator)

def unregister():
bpy.utils.unregister_class(ModalTimerOperator)

if name == "main":
register()

# test call
bpy.ops.wm.modal_timer_operator()

def unregister():
bpy.utils.unregister_class(ModalTimerOperator)

if name == "main":
register()

# test call
bpy.ops.wm.modal_timer_operator()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions