Node Wrangler: Add more specific poll methods
[blender-addons.git] / io_import_palette / import_krita.py
bloba784a3503b29d4de2f5fb927a094a0df3bef75b8
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 """
7 This script imports a Krita/Gimp Palette to Blender.
9 Usage:
10 Run this script from "File->Import" menu and then load the desired KPL file.
11 """
13 import bpy
14 import os
15 import struct
18 def load(context, filepath):
19 (path, filename) = os.path.split(filepath)
21 pal = None
22 valid = False
23 finput = open(filepath)
24 line = finput.readline()
26 while line:
27 if valid:
28 # Create Palette
29 if pal is None:
30 pal = bpy.data.palettes.new(name=filename)
32 # Create Color
33 values = line.split()
34 col = [0, 0, 0]
35 col[0] = int(values[0]) / 255.0
36 col[1] = int(values[1]) / 255.0
37 col[2] = int(values[2]) / 255.0
39 palcol = pal.colors.new()
40 palcol.color[0] = col[0]
41 palcol.color[1] = col[1]
42 palcol.color[2] = col[2]
44 if line[0] == '#':
45 valid = True
47 line = finput.readline()
49 finput.close()
51 return {'FINISHED'}