0
$\begingroup$

enter image description here

Tools generally have three stages:

1 Enter mode 2 Run and edit 3 Exit mode

In the running edit mode, you can usually rotate the view

enter image description here

How can I use Python to develop a new tool, maybe it can be called a transform tool.


 class MayaTransformComponents(bpy.types.Operator):
    bl_idname = "object.maya_transform_components"
    bl_label = "Maya Smart Transform Components"

    def execute(self, context):
        context.scene.transform_orientation_slots[0].type = 'NORMAL'
        bpy.ops.object.smart_move_tool()
        return {'RUNNING_MODAL'}

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

        if event.type in {'LEFTMOUSE', 'RIGHTMOUSE'}:
            return {'FINISHED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        context.window_manager.modal_handler_add(self)
        return self.execute(context)

Many of the tools that come with blender can rotate the view. How is this achieved?

enter image description here

In this example, I can use Alt + Left Mouse Button to move the view before running this operator. When I enter this operator, I can see that the coordinate axis is set to normal, but I can't rotate the view at this time. All I can do is end and exit this operator.

$\endgroup$
5
  • 5
    $\begingroup$ If left as it is currently written, this question should be closed as too broad since it's asking to teach Python in general in one answer or it could also be closed as lacking clarity or detail since no code from described attempts is provided and so it's impossible to say what the problems might be, also goals are not clear at all. You should definitely edit this question, narrow it down to a specific problem, describe it in detail provide context about what and why you are trying to do and also provide all the relevant detail about what you have tried and the code you have as far. $\endgroup$ Commented Jun 25 at 17:29
  • 3
    $\begingroup$ Yeah, I would edit the question with attempts you've made, the code you've got so far, specific problems, what you're expecting/ what is happening in your example etc. $\endgroup$
    – Jakemoyo
    Commented Jun 25 at 18:30
  • $\begingroup$ Here you can find some info about making new tools: b3d.interplanety.org/en/creating-custom-tool-in-blender blenderartists.org/t/adding-my-tool-to-the-toolbar-blender-2-80/… $\endgroup$
    – Crantisz
    Commented Jun 26 at 13:57
  • $\begingroup$ To clarify, do you want a tool with a gizmo as those in the Toolbar, or just a modal operator as what when you hit G, R or S to Move, Rotate or Scale? As for the modal operator definition being qable to let you control the viewpoint, perhaps adding this to the modal function would do the trick. $\endgroup$
    – Lauloque
    Commented Jun 26 at 15:35
  • $\begingroup$ Yes, this is just a simple tool, no need to show up in the toolbar, no need for an icon, just an operator, but this operator allows the axes to be set to NORMAL during the modal operation, and I can inherit the viewport rotation/translation/zoom, and the axes should be set to global when I exit this operator. In my opinion, this little feature is really no different from other "tool" types. It is frustrating that I currently cannot adjust the viewport in the modal. $\endgroup$
    – VeengLoong
    Commented Jun 26 at 16:10

0

You must log in to answer this question.

Browse other questions tagged .