0
$\begingroup$

EDIT

I've moved a different way. Using ray_cast to get face location and normal. Applying the normal to the empty vector is now my challenge :)

EDIT

I'm writing an addon that I need to interactively move an empty and have it snap and align to any face the mouse runs over, exactly like the move command with snapping active, I'd also like the user to be able to manipulate the viewport during this but bpy.ops.transform.translate("INVOKE_DEFAULT") does not allow this behavior.

I thought I could run bpy.ops.transform.translate("INVOKE_DEFAULT") then kill it on a MIDDLEMOUSE PRESS event in my modal (like when pressing ESC), then start it again on a MIDDLEMOUSE RELEASE event. 2 problems with this, I can't find a way to terminate the translate operator from code (despite many hours searching) and if it's started from within my modal the events don't seem to get passed through anymore, I'm assuming because it runs as a modal and running modals from modals is not a good idea.

Is there a way to force bpy.ops.transform.translate("INVOKE_DEFAULT") to allow viewport manipulation explicitly? Or would I have to make my own operator? (no idea even where to start with the snapping bit)

How do you terminate a bpy.ops (that's running as a modal) from code?

Is there another way?

$\endgroup$
5
  • $\begingroup$ The common idea is return {'PASS_THROUGH'} in operator when pan/rotate/scale viewport, otherwise return {'RUNNING_MODAL'} blender.stackexchange.com/questions/259016/… $\endgroup$
    – X Y
    Commented Jul 31, 2022 at 8:58
  • $\begingroup$ Thanks @XY This is how I have my modal set up. The problem is if I start bpy.ops.transform.translate("INVOKE_DEFAULT") from within my modal, the events stop being passed through $\endgroup$
    – Psyonic
    Commented Jul 31, 2022 at 9:18
  • $\begingroup$ If bpy.ops.transform.translate modal is running, it can't run another operator modal until it finish. Also should be avoid to use ops in operator. $\endgroup$
    – X Y
    Commented Jul 31, 2022 at 9:45
  • $\begingroup$ Yep, this is my problem. Do you know how to force an ops to terminate via code? $\endgroup$
    – Psyonic
    Commented Jul 31, 2022 at 9:51
  • $\begingroup$ No, it can't force an ops to terminate as it will cause issue/bugs in some cases unless the ops has this capability. I don't think most build-in ops have this feature. $\endgroup$
    – X Y
    Commented Jul 31, 2022 at 17:09

0

You must log in to answer this question.

Browse other questions tagged .