--Swatches Version 1 --by garrickcampsey (FEB.2011) - garrick@garrickcampsey.com global swatchesRollout try destroyDialog swatchesRollout catch() rollout swatchesRollout " Swatches V1" ( --Index local myColMin = [100,100,100] local myColMax = [200,200,200] local Swatch_file --the file address to the user chosen swatch local alphaStr = "0123456789ABCDEF"; local alphaArr = #("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F") --fns fn zmStringToPoint3 v = ( local pa = filterString v "[]," point3 (pa[1] as float) (pa[2] as float) (pa[3] as float) ) -- fn convertColor hexColor = ( value1= 0 value2= 0 case hexColor[1] of ( "1":(value1=1*16) "2":(value1=2*16) "3":(value1=3*16) "4":(value1=4*16) "5":(value1=5*16) "6":(value1=6*16) "7":(value1=7*16) "8":(value1=8*16) "9":(value1=9*16) "A":(value1=10*16) "B":(value1=11*16) "C":(value1=12*16) "D":(value1=13*16) "E":(value1=14*16) "F":(value1=15*16) "a":(value1=10*16) "b":(value1=11*16) "c":(value1=12*16) "d":(value1=13*16) "e":(value1=14*16) "f":(value1=15*16) ) case hexColor[2] of ( "1":(value2=1) "2":(value2=2) "3":(value2=3) "4":(value2=4) "5":(value2=5) "6":(value2=6) "7":(value2=7) "8":(value2=8) "9":(value2=9) "A":(value2=10) "B":(value2=11) "C":(value2=12) "D":(value2=13) "E":(value2=14) "F":(value2=15) "a":(value2=10) "b":(value2=11) "c":(value2=12) "d":(value2=13) "e":(value2=14) "f":(value2=15) ) newDecValue = value1 + value2 return newDecValue ) --UI label lab00 "__________________________________________" pos:[10,22] label lab01 "__________________________________________" pos:[10,136] label lab02 "__________________________________________" pos:[10,167] label lab1 "Load swatch :" pos:[10,10] button openSwatchFileCB "Click Here" checked:false pos:[82,7] width:185 height:20 colorpicker myCP1 color:(random myColMin myColMax) fieldWidth:50 height:102 pos:[5,40] colorpicker myCP2 color:(random myColMin myColMax) fieldWidth:50 height:102 pos:[57,40] colorpicker myCP3 color:(random myColMin myColMax) fieldWidth:50 height:102 pos:[109,40] colorpicker myCP4 color:(random myColMin myColMax) fieldWidth:50 height:102 pos:[161,40] colorpicker myCP5 color:(random myColMin myColMax) fieldWidth:50 height:102 pos:[213,40] label lab3 "Save Name :" pos:[10,157] enabled:false edittext saveObjektNameET text:"objekt" fieldWidth:100 height:17 pos:[75,155] enabled:false button folderObjektFileBTN "Folder" checked:false pos:[183,155] width:40 height:17 enabled:false button saveObjektFileBTN "Save" checked:false pos:[223,155] width:38 height:17 enabled:false --EVENTS on openSwatchFileCB pressed do ( Swatch_file = getOpenFileName caption:"Open Swatch file (.ase)" filename:(GetDir #scripts+"\\") types:"script(*.ase)|*.ase|" if Swatch_file != undefined and (getFilenameType Swatch_file) == ".ase" then ( local buffer local ss = fopen Swatch_file "rb" if ss != undefined do ( buffer = #() while (val = ReadByte ss #unsigned) != undefined and not keyboard.escpressed do (append buffer val) fflush ss fclose ss ) local myCharBits = #() for i = 1 to buffer.count do ( local charBit = bit.intAsChar buffer[i] append myCharBits charBit ) local myCharStream = stringStream "" for i = 1 to myCharBits.count do (format "%" myCharBits[i] to:myCharStream) local myCharString = myCharStream as string local myFilterString = filterString myCharString "#" --print myFilterString --myFilterString[1] is the name of the swatch --clean up mess before name, first 10 digits local mySwatchNameLong = substring myFilterString[1] 11 100 local mySwatchName = filterString mySwatchNameLong "$" local mySwatchNameTrimmed = substring mySwatchName[1] 1 (mySwatchName[1].count-1) openSwatchFileCB.text = mySwatchNameTrimmed --myFilterString[2] - [7] are the RGB values in hex form local myHexColorsArray = #() for i = 2 to 6 do ( local myColorString = filterString myFilterString[i] "R" append myHexColorsArray myColorString[1] ) try( --some swatches have their data spread to a 7th entry, some dont local myColorString = filterString myFilterString[7] "R" append myHexColorsArray myColorString[1] )catch() --print myHexColorsArray --ex:"B5CC7A" -- local myRGBColorsArray = #() for i = 1 to 5 do ( local firstTwo = (myHexColorsArray[i][1] as string)+(myHexColorsArray[i][2] as string) local secondTwo = (myHexColorsArray[i][3] as string)+(myHexColorsArray[i][4] as string) local thirdTwo = (myHexColorsArray[i][5] as string)+(myHexColorsArray[i][6] as string) local firstTwoConverted = convertColor firstTwo local secondTwoConverted = convertColor secondTwo local thirdTwoConverted = convertColor thirdTwo -- local myCharStream = stringStream "" format "[%,%,%]" firstTwoConverted secondTwoConverted thirdTwoConverted to:myCharStream local myCharString = myCharStream as string --print myCharString append myRGBColorsArray myCharString ) try( --check for the 6th one local firstTwo = (myHexColorsArray[6][1] as string)+(myHexColorsArray[6][2] as string) local secondTwo = (myHexColorsArray[6][3] as string)+(myHexColorsArray[6][4] as string) local thirdTwo = (myHexColorsArray[6][5] as string)+(myHexColorsArray[6][6] as string) local firstTwoConverted = convertColor firstTwo local secondTwoConverted = convertColor secondTwo local thirdTwoConverted = convertColor thirdTwo -- local myCharStream = stringStream "" format "[%,%,%]" firstTwoConverted secondTwoConverted thirdTwoConverted to:myCharStream local myCharString = myCharStream as string --print myCharString append myRGBColorsArray myCharString )catch() --print myRGBColorsArray --ex: "[41,11,28]" -- local mySixthValue try(mySixthValue = zmStringToPoint3 myRGBColorsArray[6])catch();--print mySixthValue -- for i = 1 to 5 do ( local myPoint3value = zmStringToPoint3 myRGBColorsArray[i] if i == 1 then (myCP1.color = (myPoint3value as color)) if i == 2 then (myCP2.color = (myPoint3value as color)) if i == 3 then (myCP3.color = (myPoint3value as color)) if i == 4 then (myCP4.color = (myPoint3value as color)) if i == 5 then (myCP5.color = (myPoint3value as color)) ) --check the color values, pure black values are invalid data, replace with optional 6th value if myCP1.color == ([0,0,0] as color) then ( myCP1.color = myCP2.color;myCP2.color = myCP3.color myCP3.color = myCP4.color;myCP4.color = myCP5.color myCP5.color = mySixthValue ) if myCP2.color == ([0,0,0] as color) then ( myCP2.color = myCP3.color;myCP3.color = myCP4.color;myCP4.color = myCP5.color myCP5.color = mySixthValue ) if myCP3.color == ([0,0,0] as color) then ( myCP3.color = myCP4.color;myCP4.color = myCP5.color myCP5.color = mySixthValue ) if myCP4.color == ([0,0,0] as color) then ( myCP4.color = myCP5.color myCP5.color = mySixthValue ) if myCP5.color == ([0,0,0] as color) then (myCP5.color = mySixthValue) -- ) --end if/then )--on openSwatchFileCB pressed do () --the standard button launchBTN "< Indexr" pos:[10,185] width:50 height:20 on launchBTN pressed do (try(fileIn "indexr.ms")catch(messagebox "Cannot find indexr.ms")) button whoIsBTN "?" pos:[60,185] width:15 height:20 on whoIsBTN pressed do (messagebox "Send errors to: Garrick@GarrickCampsey.com") )--close rollout createDialog swatchesRollout 275 215 5 50 lockWidth:true lockHeight:true style:#(#style_toolwindow, #style_sysmenu, #style_resizing)