my apologies, as james mentioned before, there are a few properties that return a decimal that need to be overridden and converted into a single so that max doesnt do the integer conversion.
I’ve updated the control so it should now return a float in max by using value,minimum,maximum and increment.
(click the image to download)
I have also added right click to reset functionality too.
Hi all,
Further to some feedback to the control i’ve added it to my lonerobot.net blogas a tutorial. It also includes the source code so that you can pick apart building a custom control for max. I was thinking I might write a tutorial series on writing custom controls for max if it would be useful.
About the conversion problem with the NumericUpDown control, I have found the way to get over it.
Using getProperty <dotNetObject> <prop name> [asDotNetObject:<bool>] to get the decimal value without MAXScript conversion and using Decimal.ToSingle().
See on btnGetValue MouseClick event handler :
(
rollout upDownRolloutTest "NumericUpDown Control Test" width:220 height:45
(
dotNetControl upDownCtrl "System.Windows.Forms.NumericUpDown" pos:[10,10] width:50 height:25
dotNetControl btnGetValue "System.Windows.Forms.Button" pos:[90,10] width:100 height:21
on upDownRolloutTest open do
(
upDownCtrl.DecimalPlaces = 1
upDownCtrl.Increment = 0.1
upDownCtrl.Value = 1.0
upDownCtrl.Minimum = 0.0
upDownCtrl.Maximum = 10.0
btnGetValue.Text = "Get Value"
btnGetValue.FlatStyle = (dotNetClass "System.Windows.Forms.FlatStyle").System
)
on btnGetValue MouseClick do
(
-- Get the value auto converted by MAXScript
fValue = upDownCtrl.Value
format "Wrong Value : %
" fValue
-- Get the decimal value as a .NET object
dValue = getProperty upDownCtrl #value asDotNetObject:true
-- Convert it to single object value then auto converted to float value by MAXScript
fValue = (dotNetClass "System.Decimal").ToSingle dValue
format "Good Value : %
" fValue
)
)
createDialog upDownRolloutTest
)
I’ve added your solution to my blog entry Yannick, hope that is okay. cheers!
No problem Pete. Thanks also for the info about MaxSpinner wrapper in Managed Services assembly.