How to create Macros? (Without operator)

Let’s say for example I want to run these commands for automation purposes:


import bpy
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.remove_doubles()
bpy.ops.mesh.tris_convert_to_quads()
bpy.ops.mesh.select_all(action='TOGGLE')

Unfortunately they can’t run from the text editor, they must be put into a new operator so they are within context. What I am trying to find is a hack that will allow this to happen.

P.S. The most obvious solution is to create a new operator, but this approach is simply “too much effort” considering macros need to be as thin as possible and to be created simply.

OK, this is the best way to make macros. Lots of thanks batFINGER.

Here is what I did in this case:


import bpy


# Set edit mode
# This can run in Text
bpy.ops.object.editmode_toggle()


# Currently all vertices are selected
# These can run only in 3D view
bpy.context.area.type = 'VIEW_3D'
bpy.ops.mesh.remove_doubles()
bpy.ops.mesh.tris_convert_to_quads()


# Restore object mode
bpy.context.area.type = 'TEXT_EDITOR'
bpy.ops.object.editmode_toggle()

So spread the word people, look no further and start typing macros! :smiley: