[Closed] UIControlManager & PresetManager
Hi,
in the past week I’ve been working on some general purpose scripts to make script development easier.
The UIControlManager enables you to dynamically create rollouts. During development I realised that it was quite similar to the rolloutcreator script provided by autodesk. However, it has some more features:
[ul]
[li]It doesn’t write the rollout string immediately, but on command (so at the end).[/li][li]You can add a ‘child connection’ for controls, enabling you to link the enabled state of one or more controls to the checked state of a checkbox. This saves you a lot of event writing.[/li][li]You can add a ‘var link’ for controls. This automatically adds an event to make sure that a variable value is updated each time the control is updated.[/li][li]You can add a ‘spinner connection’. This ‘links’ two spinner values. So if you change one, the other is updated to be either lower/heigher or to represent a certain ratio.[/li][li]You can use groups.[/li][/ul]The PresetManager provides an easy way to load and save presets.
Presets are saved in an ini file, and are loaded into one or more structures.
Download links:
UIControlManager
PresetManager
I’d like to hear your ideas and opinions about this. If you find it useful, you can use it.
In the next post I’ll give a couple of usage examples.
Thank you.
UIControlManager usage:
Simple rollout:
fileIn "UIControlManager.ms"
sampleRollout = UIControlManager this:"sampleRollout"
sampleRollout.addControl #spinner #sampleSpinner "Sample Spinner" params:"across:2"
sampleRollout.addControl #button #sampleButton "Sample Button"
sampleRollout.openDialog caption:"Sample Rollout" width:400 height:100
[i]Simple Control Event:[/i]
fileIn "UIControlManager.ms"
sampleRollout = UIControlManager this:"sampleRollout"
sampleRollout.addControl #spinner #sampleSpinner "Sample Spinner" params:"across:2"
sampleRollout.addControlEvent #sampleSpinner code:"format \"spinner value: %
\" arg"
sampleRollout.addControl #button #sampleButton "Sample Button"
sampleRollout.addControlEvent #sampleButton code:"print \"sampleButton pressed.\""
sampleRollout.openDialog caption:"Sample Rollout" width:400 height:100
[i]Connected spinners:[/i]
fileIn "UIControlManager.ms"
sampleRollout = UIControlManager this:"sampleRollout"
sampleRollout.addControl #spinner #firstSpinner "Spinner 1" params:"across:2"
sampleRollout.addControl #spinner #secondSpinner "Spinner 2"
sampleRollout.addSpinnerConnection #firstSpinner #secondSpinner type:#constrain param:5
sampleRollout.openDialog caption:"Sample Rollout" width:400 height:100
[i] Variable connection:[/i]
fileIn "UIControlManager.ms"
global testVar = 10
sampleRollout = UIControlManager this:"sampleRollout"
sampleRollout.addControl #spinner #sampleSpinner "Sample Spinner" params:"across:2"
sampleRollout.addVarLink #sampleSpinner #value "testVar"
sampleRollout.addControl #button #sampleButton "Sample Button"
sampleRollout.openDialog caption:"Sample Rollout" width:400 height:100
sampleRollout.updateControlValues()
[i] Child reference:[/i]
fileIn "UIControlManager.ms"
sampleRollout = UIControlManager this:"sampleRollout"
sampleRollout.addControl #checkbox #sampleCheckbox "Check to Enable"
sampleRollout.addControl #spinner #sampleSpinner "Sample Spinner" params:"across:2"
sampleRollout.addControl #button #sampleButton "Sample Button"
sampleRollout.addChild #sampleCheckbox childControls:#(#sampleSpinner, #sampleButton)
sampleRollout.openDialog caption:"Sample Rollout" width:400 height:100
sampleRollout.updateAllChildren()
[i] Group:[/i]
fileIn "UIControlManager.ms"
sampleRollout = UIControlManager this:"sampleRollout"
sampleRollout.addControl #groupStart #sampleGroupStart "Sample Group"
sampleRollout.addControl #spinner #sampleSpinner "Sample Spinner" params:"across:2"
sampleRollout.addControl #button #sampleButton "Sample Button"
sampleRollout.addControl #groupEnd #sampleGroupEnd "Sample Group"
sampleRollout.openDialog caption:"Sample Rollout" width:400 height:100
You can of course combine all these features.
Some notes:
[ul]
[li]When using events, the first argument (if available) is always ‘arg’, the second (if available) is ‘arg2’.[/li][li]When creating child references, not supplying the childControls value results in all controls being set as children of the selected control.[/li][li]When using a control that already has child references as a child to another checkbox (so you’ve got a checkbox that enables/disables a checkbox which in turn enables/disables other controls), don’t supply the ‘lowest’ controls in the higher checkbox. If you don’t, the higher checkbox will override the lower.[/li][li]When refering to controls when the rollout is created, use ‘theUIControlManagerInstance.finishedRollout.control’ or ‘theUIControlManagerInstance.finishedRollout.controls[controlnumber]’[/li]
[/ul]
PresetManager usage:
Add a new preset:
struct sampleStruct (
setting1, setting2, setting3
)
global sampleSettings = sampleStruct setting1:3 setting2:"sample" setting3:18
fileIn "presetManager.ms"
global presetManager = presetManager presetDir:"sampleDir"
presetManager.addPreset name:"Sample Preset" sections:#("SampleSettings") structures:#("sampleSettings")
Get presets from directory:
struct sampleStruct (
setting1, setting2, setting3
)
global sampleSettings = sampleStruct()
fileIn "presetManager.ms"
global presetManager = presetManager presetDir:"sampleDir"
presetManager.getPresetsFromDir "sampleDir"
Load and save preset:
struct sampleStruct (
setting1, setting2, setting3
)
global sampleSettings = sampleStruct()
fileIn "presetManager.ms"
global presetManager = presetManager presetDir:"sampleDir"
presetManager.getPresetsFromDir "sampleDir"
presetManager.loadPreset 1
presetManager.savePreset 1
Thanks for sharing this!
What I really like is the possibility to mix addControll and addEvent methods.
Georg