1 Star 0 Fork 0

tangyin025/TexTools-Blender

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
op_color_io_import.py 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
franMarz 提交于 2023-02-22 01:39 +08:00 . Use a exact context for operators
import bpy
import string
from . import utilities_color
class op(bpy.types.Operator):
bl_idname = "uv.textools_color_io_import"
bl_label = "Import"
bl_description = "Import hex colors from the clipboard as current color palette"
@classmethod
def poll(cls, context):
if bpy.context.area.ui_type != 'UV':
return False
return True
def execute(self, context):
import_colors(self, context)
return {'FINISHED'}
def import_colors(self, context):
# Clipboard hex strings
hex_strings = bpy.context.window_manager.clipboard.split(',')
for i in range(len(hex_strings)):
hex_strings[i] = hex_strings[i].strip().strip('#')
if len(hex_strings[i]) != 6 or not all(c in string.hexdigits for c in hex_strings[i]):
# Incorrect format
self.report({'ERROR_INVALID_INPUT'}, "Incorrect hex format '{}' use a #RRGGBB pattern".format(hex_strings[i]))
return
else:
name = "color_ID_color_{}".format(i)
if hasattr(bpy.context.scene.texToolsSettings, name):
# Color Index exists
color = utilities_color.hex_to_color( hex_strings[i] )
setattr(bpy.context.scene.texToolsSettings, name, color)
else:
# More colors imported than supported
self.report({'ERROR_INVALID_INPUT'}, "Only {}x colors have been imported instead of {}x".format(
i,len(hex_strings)
))
return
# Set number of colors
bpy.context.scene.texToolsSettings.color_ID_count = len(hex_strings)
bpy.ops.ui.textools_popup('INVOKE_DEFAULT', message="{}x colors imported from clipboard".format( len(hex_strings) ))
bpy.utils.register_class(op)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tangyin025/TexTools-Blender.git
[email protected]:tangyin025/TexTools-Blender.git
tangyin025
TexTools-Blender
TexTools-Blender
master

搜索帮助