Post #5102: It seems like you’ve put together quite an elaborate setup. As you’ve realized,
📋 Metadata
- Author: Pluglug
- Date: 2024-04-19 14:04:29
- Type:
answer - Quality Score: 8/10
- Reply to: post_05100
🏷️ Tags
pie-menu hotkeys configuration advanced solved
⚙️ Related PME Features
- Stack Key Editor
- Python Scripting
- Menu Editor
- Popup Dialog Editor
💬 Content
It seems like you’ve put together quite an elaborate setup. As you’ve realized, handling things with Poll has its limitations. Poll is meant to ensure that an operation can be safely executed in a given context, so you can choose a better approach.
What’s amazing is that roaoao has anticipated cases like this and already provides the functionality you need.
Here’s a detailed explanation of how to use it:
First, make sure that scripts\command_context_sensitive_menu.py exists.
Next, import examples\context_sensitive_menu.json.
If you look at the imported menu, you’ll see that the Stack Key “Context Sensitive Menu” (hereafter referred to as CSM) is set.
CSM has a command registered: execute_script("scripts/command_context_sensitive_menu.py", prefix="CSM: "). This can be interpreted as instructing the script to select any menu with the prefix “CSM: “.
To use CSM, you need to prepare the necessary menus in advance. The menu names must follow a specific naming convention that includes the prefix.
In this case, you need to prepare menus with the prefix “CSM: “. Here are some examples of menu names:
Required
CSM: None Object: Menu called when no object is selectedCSM: Any Object: Menu called when no other conditions are met
Optional
CSM: Mesh: Menu called when a mesh object is selectedCSM: Vertex: Menu called when a mesh object is in edit mode and vertices are selectedCSM: Edge: Menu called when a mesh object is in edit mode and edges are selectedCSM: Face: Menu called when a mesh object is in edit mode and faces are selectedCSM: Armature: Menu called when an armature object is selectedCSM: Pose: Menu called in pose modeCSM: Light: Menu called when a light object is selectedCSM: Edit: Menu called in edit mode (see note below)
You can find more usable words on the following pages:
object mode items
object type items
Please note that terms like VERTEX_PAINT need to be changed to Vertex Paint.
When CSM is executed, it will call the menu "CSM: " + (selected object's type name or mode name) based on the selected object.
This allows you to automatically call the appropriate menu depending on the situation.
One thing to note is that if you create an “Edit” menu, for example, edit mode for armatures and lattices will not be distinguished. To solve this, you need to customize the script to use context.mode.
I plan to enhance this feature in the future. Specifically, I’ll change it to use context.mode instead of object.mode, and add further options for when object.type == 'EMPTY'.
If anyone has any good ideas, please let me know.
That covers the explanation, but if you have any questions or further requests, please let me know.
❤️ 5 likes
image866×402 34.6 KB