Hi,

I have a question regarding the use of an external data file (json).

Indeed, in my case, the user enters the value of the RAL (integer number) and, with this value, the script finds the name and the RGB equivalence of this color.

This works fine but I'm wondering what would be the best method to block entering an impossible value (if RAL doesn't exist).

JSON =>

{
	"color":
	[
		{
			"hue": "yellow",
			"ral": 1000,
			"red": 205,
			"green": 186,
			"blue": 136,
			"hex": "#cdba88",
			"name_en": "green beige",
			"name_fr": "beige vert"
		},
...

PYTHONPART =>

   # Check color
    if value_name == "ColorStandardFace1":    
 
        file = AllplanSettings.AllplanPaths.GetCurPrjPath() + "ral.json"
        f = open(file, "r") 
        data = json.load(f) 

        for i in data['color']:
            if i['ral'] == build_ele.ColorStandardFace1.value :
                build_ele.NameColorStandardFace1.value = i['name_fr']                    
                rgb = AllplanBasisElements.ARGB (i['red'], i['green'], i['blue'], 0)
                build_ele.PreviewColorStandardFace1.value = AllplanBaseElements.GetIdByColor(rgb)

        f.close()        

        return True

Best
Christophe

Attachments (1)

Type: image/png
Downloaded 54 times
Size: 16,10 KiB