Created
September 29, 2024 20:31
-
-
Save tin2tin/17e2055d1ec70095cd655a110a31675d to your computer and use it in GitHub Desktop.
Does operator exist?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
def operator_exists(idname): | |
# Split the idname string into the operator type and the operator function | |
idname_parts = idname.split(".") | |
if len(idname_parts) != 2: | |
return False # The idname is not properly formatted | |
operator_type, operator_func = idname_parts | |
# Check if the operator type and function exist in bpy.ops | |
return hasattr(getattr(bpy.ops, operator_type, None), operator_func) | |
# Example usage: | |
print(operator_exists("sequencer.generate_image")) # Returns True if the operator exists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment