Post #428: Mighty Pea:

📋 Metadata

  • Author: roaoao
  • Date: 2016-11-10 07:45:22
  • Type: answer
  • Quality Score: 8/10
  • Reply to: post_00427

🏷️ Tags

pie-menu scripting intermediate solved

  • Pie Menu Editor
  • Python Scripting
  • wm.pme_user_command_exec operator
  • Custom Icons

💬 Content

Mighty Pea:

Would it be possible to set some of the Modifier’s settings on creation?
For instance, I’d like to set the type to Bend and the angle to 360 by default.

The script I’m using:
mods = [m for m in C.active_object.modifiers if m.type == ‘SIMPLE_DEFORM’]; m = mods and mods[0]; L.prop(m, “angle”, “angle”) if m else operator(L, “object.modifier_add”, “Add Bend”, ‘ZOOMIN’, type=‘SIMPLE_DEFORM’)

Hi, Mighty Pea.
wm.pme_user_command_exec operator can be useful here. It executes python code from cmd property:

mods = [m for m in C.active_object.modifiers if m.type == 'SIMPLE_DEFORM']; m = mods and mods[0]; L.prop(m, "angle", "angle") if m else operator(L, "wm.pme_user_command_exec", "Add Bend", 'ZOOMIN', cmd="execute_script('scripts/simple_bend.py')")

So if you press Add Bend button it will execute scripts/simple_bend.py file:

import math
O.object.modifier_add(type='SIMPLE_DEFORM')
last_modifier = C.object.modifiers[-1]
last_modifier.deform_method = 'BEND'
last_modifier.angle = 2 * math.pi

🔗 View on Blender Artists