Post #239: Mighty Pea:
📋 Metadata
- Author: roaoao
- Date: 2016-07-29 09:05:53
- Type:
answer - Quality Score: 9/10
- Reply to: post_00237
🏷️ Tags
v1-10-1 popup-dialog pie-menu custom-scripting advanced solved
⚙️ Related PME Features
- Custom tab scripting
- Modifier operators
- Context toggling
- Property controls
- Macro Editor
💬 Content
Mighty Pea:
I’m trying to create a command that adds a Subsurf modifier to an object if it doesn’t already have one, and when there is one, will toggle its visibility on and off.
This code will work in the next (v1.10.1) version. I’ll release it today. Use the code in Custom tab:
mods = [m for m in C.active_object.modifiers if m.type == 'SUBSURF']; m = mods and mods[0]; operator(L, "wm.context_toggle", text, icon, icon_value=icon_value, data_path="active_object.modifiers['%s'].show_viewport" % m.name) if m else operator(L, "object.modifier_add", text, icon, icon_value=icon_value, type='SUBSURF')
Mighty Pea:
Similarly, I have a ‘Subdivisions’ slider in a popup, which is great, but: if the object has no subsurf modifier, there’s an empty space where the control would normally be, and it messes with the layout:
[ATTACH=CONFIG]446827[/ATTACH] [ATTACH=CONFIG]446828[/ATTACH]
It’d be great if the slider could just be a button to add the subsurf modifier when there’s none present.
This code will work in the next (v1.10.1) version. Use it in Custom tab:
mods = [m for m in C.active_object.modifiers if m.type == 'SUBSURF']; m = mods and mods[0]; L.prop(m, "levels", "Subdivisions") if m else operator(L, "object.modifier_add", "Add Subsurf", 'ZOOMIN', type='SUBSURF')
Mighty Pea:
I couldn’t find a function to increase or decrease a subsurf’s subdivion level by 1, only to set it to a specific level. Is this possible without scripting?
If you want to assign that function to buttons use this code (Command tab):
Increase:
mods = [m for m in C.active_object.modifiers if m.type == 'SUBSURF']; m = mods and mods[0]; m and O.wm.context_cycle_int(data_path="active_object.modifiers['%s'].levels" % m.name, reverse=False)
Decrease:
mods = [m for m in C.active_object.modifiers if m.type == 'SUBSURF']; m = mods and mods[0]; m and O.wm.context_cycle_int(data_path="active_object.modifiers['%s'].levels" % m.name, reverse=True)
Mighty Pea:
Lastly, is it possible to align single buttons? I’d like to have this looking the way it does in the editor
[ATTACH=CONFIG]446829[/ATTACH]
Yes, it’s possible. You need to use
.
❤️ 1 likes