3rd Dimentia
04-14-2009, 04:41 AM
The more macros I write, the more often I'd like to be able to have the state of the UI of the macro (values,state of checkboxes etc) saved with the maxfile. I have a way to do this at the moment, by storing them in the custom file properties. But the way I'm doing it seems to be very long-winded and laborious. Not to mention convoluted :)
Below is a simple random wirecolor script with the technique that I use in it. Can anyone help me with a quicker, less verbose way to store UI state in a max file?
macroscript RandomWireColourHSV
category: "CgRay"
buttontext:"RwcHSV"
Icon:#("CgRay-RandomWireColourHSV",1)
(
clearlistener()
try (destroydialog RandomWirecolorHSV) catch()
rollout RandomWirecolorHSV "Random Wirecolor HSV"
(
progressbar col1 "" value:100 color:red height:8 width:38 align:#right offset:[26,0] across:2
progressbar col2 "" value:100 color:red height:8 width:38 align:#right offset:[0,0]
label huelabel "Hue Range" align:#left across:3
spinner spn_huelow range:[0,255,0] type:#integer width:40 align:#right
spinner spn_huehigh range:[0,255,255] type:#integer width:40 align:#right
label satlabel "Sat Range" align:#left across:3
spinner spn_satlow range:[0,255,0] type:#integer width:40 align:#right
spinner spn_sathigh range:[0,255,255] type:#integer width:40 align:#right
label vallabel "Val Range" align:#left across:3
spinner spn_vallow range:[0,255,0] type:#integer width:40 align:#right
spinner spn_valhigh range:[0,255,255] type:#integer width:40 align:#right
label randomise "Randomise:" align:#left across:3
button btn_selected "Selected" align:#right offset:[19,0] across:2
button btn_all "All" align:#right
fn checkLow &lowVal &highVal =
(
if lowVal > highVal do
(
highval = lowval
)
)
fn checkHigh &lowVal &highVal =
(
if lowVal > highVal do
(
lowval = highval
)
)
fn hueChange =
(
tempcol2 = RandomWirecolorHSV.col1.color
tempcol2.h = RandomWirecolorHSV.spn_huelow.value
RandomWirecolorHSV.col1.color = tempcol2
tempcol3 = RandomWirecolorHSV.col2.color
tempcol3.h = RandomWirecolorHSV.spn_huehigh.value
RandomWirecolorHSV.col2.color = tempcol3
)
fn FilePropInit =
(
HueLowIndex = fileProperties.findProperty #custom "HueLow"
HueHighIndex = fileProperties.findProperty #custom "HueHigh"
SatLowIndex = fileProperties.findProperty #custom "SatLow"
SatHighIndex = fileProperties.findProperty #custom "SatHigh"
ValLowIndex = fileProperties.findProperty #custom "ValLow"
ValHighIndex = fileProperties.findProperty #custom "ValHigh"
if HueLowIndex != 0 then
( RandomWirecolorHSV.spn_huelow.value = fileProperties.getPropertyValue #custom HueLowIndex
hueChange()
)
if HueHighIndex != 0 then
( RandomWirecolorHSV.spn_huehigh.value = fileProperties.getPropertyValue #custom HueHighIndex
hueChange()
)
if SatLowIndex != 0 then
( RandomWirecolorHSV.spn_satlow.value = fileProperties.getPropertyValue #custom SatLowIndex
)
if SatHighIndex != 0 then
( RandomWirecolorHSV.spn_sathigh.value = fileProperties.getPropertyValue #custom SatHighIndex
)
if ValLowIndex != 0 then
( RandomWirecolorHSV.spn_vallow.value = fileProperties.getPropertyValue #custom ValLowIndex
)
if ValHighIndex != 0 then
( RandomWirecolorHSV.spn_valhigh.value = fileProperties.getPropertyValue #custom ValHighIndex
)
)
fn changeHueProp =
(
fileProperties.addProperty #custom "HueLow" (RandomWirecolorHSV.spn_huelow.value)
fileProperties.addProperty #custom "HueHigh" (RandomWirecolorHSV.spn_huehigh.value)
)
fn changeSatProp =
(
fileProperties.addProperty #custom "SatLow" (RandomWirecolorHSV.spn_satlow.value)
fileProperties.addProperty #custom "SatHigh" (RandomWirecolorHSV.spn_sathigh.value)
)
fn changeValProp =
(
fileProperties.addProperty #custom "ValLow" (RandomWirecolorHSV.spn_vallow.value)
fileProperties.addProperty #custom "ValHigh" (RandomWirecolorHSV.spn_valhigh.value)
)
on RandomWirecolorHSV open do
( FilePropInit ()
)
on spn_huelow changed huelowval do
( checkLow &spn_huelow.value &spn_huehigh.value
changeHueProp ()
hueChange ()
)
on spn_huehigh changed huehighval do
( checkHigh &spn_huelow.value &spn_huehigh.value
changeHueProp ()
hueChange ()
)
on spn_satlow changed satlowval do
( checkLow &spn_satlow.value &spn_sathigh.value
changeSatProp ()
)
on spn_sathigh changed sathighval do
( checkHigh &spn_satlow.value &spn_sathigh.value
changeSatProp ()
)
on spn_vallow changed vallowval do
( checkLow &spn_vallow.value &spn_valhigh.value
changeValProp ()
)
on spn_valhigh changed valhighval do
( checkHigh &spn_vallow.value &spn_valhigh.value
changeValProp ()
)
on btn_selected pressed do
(
if selection.count !=0 then
(
for obj in selection do
(
hue = (random spn_huelow.value spn_huehigh.value)
sat = (random spn_satlow.value spn_sathigh.value)
val = (random spn_vallow.value spn_valhigh.value)
tempColor = color 0 0 0
tempColor.v = val
tempColor.s = sat
tempColor.h = hue
obj.wirecolor = tempColor
)
)
else
(
messagebox "Select something first"
)
)
on btn_all pressed do
(
if objects.count !=0 then
(
for obj in objects do
(
hue = (random spn_huelow.value spn_huehigh.value)
sat = (random spn_satlow.value spn_sathigh.value)
val = (random spn_vallow.value spn_valhigh.value)
tempColor = color 0 0 0
tempColor.v = val
tempColor.s = sat
tempColor.h = hue
obj.wirecolor = tempColor
)
)
else
(
messagebox "No objects in scene"
)
)
)
createdialog RandomWirecolorHSV 185 110
)
Below is a simple random wirecolor script with the technique that I use in it. Can anyone help me with a quicker, less verbose way to store UI state in a max file?
macroscript RandomWireColourHSV
category: "CgRay"
buttontext:"RwcHSV"
Icon:#("CgRay-RandomWireColourHSV",1)
(
clearlistener()
try (destroydialog RandomWirecolorHSV) catch()
rollout RandomWirecolorHSV "Random Wirecolor HSV"
(
progressbar col1 "" value:100 color:red height:8 width:38 align:#right offset:[26,0] across:2
progressbar col2 "" value:100 color:red height:8 width:38 align:#right offset:[0,0]
label huelabel "Hue Range" align:#left across:3
spinner spn_huelow range:[0,255,0] type:#integer width:40 align:#right
spinner spn_huehigh range:[0,255,255] type:#integer width:40 align:#right
label satlabel "Sat Range" align:#left across:3
spinner spn_satlow range:[0,255,0] type:#integer width:40 align:#right
spinner spn_sathigh range:[0,255,255] type:#integer width:40 align:#right
label vallabel "Val Range" align:#left across:3
spinner spn_vallow range:[0,255,0] type:#integer width:40 align:#right
spinner spn_valhigh range:[0,255,255] type:#integer width:40 align:#right
label randomise "Randomise:" align:#left across:3
button btn_selected "Selected" align:#right offset:[19,0] across:2
button btn_all "All" align:#right
fn checkLow &lowVal &highVal =
(
if lowVal > highVal do
(
highval = lowval
)
)
fn checkHigh &lowVal &highVal =
(
if lowVal > highVal do
(
lowval = highval
)
)
fn hueChange =
(
tempcol2 = RandomWirecolorHSV.col1.color
tempcol2.h = RandomWirecolorHSV.spn_huelow.value
RandomWirecolorHSV.col1.color = tempcol2
tempcol3 = RandomWirecolorHSV.col2.color
tempcol3.h = RandomWirecolorHSV.spn_huehigh.value
RandomWirecolorHSV.col2.color = tempcol3
)
fn FilePropInit =
(
HueLowIndex = fileProperties.findProperty #custom "HueLow"
HueHighIndex = fileProperties.findProperty #custom "HueHigh"
SatLowIndex = fileProperties.findProperty #custom "SatLow"
SatHighIndex = fileProperties.findProperty #custom "SatHigh"
ValLowIndex = fileProperties.findProperty #custom "ValLow"
ValHighIndex = fileProperties.findProperty #custom "ValHigh"
if HueLowIndex != 0 then
( RandomWirecolorHSV.spn_huelow.value = fileProperties.getPropertyValue #custom HueLowIndex
hueChange()
)
if HueHighIndex != 0 then
( RandomWirecolorHSV.spn_huehigh.value = fileProperties.getPropertyValue #custom HueHighIndex
hueChange()
)
if SatLowIndex != 0 then
( RandomWirecolorHSV.spn_satlow.value = fileProperties.getPropertyValue #custom SatLowIndex
)
if SatHighIndex != 0 then
( RandomWirecolorHSV.spn_sathigh.value = fileProperties.getPropertyValue #custom SatHighIndex
)
if ValLowIndex != 0 then
( RandomWirecolorHSV.spn_vallow.value = fileProperties.getPropertyValue #custom ValLowIndex
)
if ValHighIndex != 0 then
( RandomWirecolorHSV.spn_valhigh.value = fileProperties.getPropertyValue #custom ValHighIndex
)
)
fn changeHueProp =
(
fileProperties.addProperty #custom "HueLow" (RandomWirecolorHSV.spn_huelow.value)
fileProperties.addProperty #custom "HueHigh" (RandomWirecolorHSV.spn_huehigh.value)
)
fn changeSatProp =
(
fileProperties.addProperty #custom "SatLow" (RandomWirecolorHSV.spn_satlow.value)
fileProperties.addProperty #custom "SatHigh" (RandomWirecolorHSV.spn_sathigh.value)
)
fn changeValProp =
(
fileProperties.addProperty #custom "ValLow" (RandomWirecolorHSV.spn_vallow.value)
fileProperties.addProperty #custom "ValHigh" (RandomWirecolorHSV.spn_valhigh.value)
)
on RandomWirecolorHSV open do
( FilePropInit ()
)
on spn_huelow changed huelowval do
( checkLow &spn_huelow.value &spn_huehigh.value
changeHueProp ()
hueChange ()
)
on spn_huehigh changed huehighval do
( checkHigh &spn_huelow.value &spn_huehigh.value
changeHueProp ()
hueChange ()
)
on spn_satlow changed satlowval do
( checkLow &spn_satlow.value &spn_sathigh.value
changeSatProp ()
)
on spn_sathigh changed sathighval do
( checkHigh &spn_satlow.value &spn_sathigh.value
changeSatProp ()
)
on spn_vallow changed vallowval do
( checkLow &spn_vallow.value &spn_valhigh.value
changeValProp ()
)
on spn_valhigh changed valhighval do
( checkHigh &spn_vallow.value &spn_valhigh.value
changeValProp ()
)
on btn_selected pressed do
(
if selection.count !=0 then
(
for obj in selection do
(
hue = (random spn_huelow.value spn_huehigh.value)
sat = (random spn_satlow.value spn_sathigh.value)
val = (random spn_vallow.value spn_valhigh.value)
tempColor = color 0 0 0
tempColor.v = val
tempColor.s = sat
tempColor.h = hue
obj.wirecolor = tempColor
)
)
else
(
messagebox "Select something first"
)
)
on btn_all pressed do
(
if objects.count !=0 then
(
for obj in objects do
(
hue = (random spn_huelow.value spn_huehigh.value)
sat = (random spn_satlow.value spn_sathigh.value)
val = (random spn_vallow.value spn_valhigh.value)
tempColor = color 0 0 0
tempColor.v = val
tempColor.s = sat
tempColor.h = hue
obj.wirecolor = tempColor
)
)
else
(
messagebox "No objects in scene"
)
)
)
createdialog RandomWirecolorHSV 185 110
)
