Delving into the DotNet SDK – A timechange callback via Dotnet

Oct 28, 2008 by     No Comments    Posted under: 3dsMax, DotNet, Technical Research

A quick look into the dotnet SDK shows a few useful classes that one can use. Over time as I discover what some are for I will hopefully be able to document some of them. One class that stuck out to me was the ManagedServices.AnimationFrameChangeListener class. After a quick inspection of the methods and properties I was able to work out how to enable this and get it talking to max – namely calling a function when the timeslider was scrubbed back and forth.

The example is just to show it working, it updates a label control on the dialog with the current frame. However, knowing that this is possible from dotnet is interesting, as in the future it might be possible to use it to bind max controllers to dotnet objects and controls. Whether it is any better or worse that the current timechange callback that MXS implements is something I’m yet to figure out. The way i see it is that it’s been put there for a reason, I’m sure a use can be found!


global DotNetTimeChangeCallback

rollout DotNetTimeCallback "DotNet Time Callback" width:194 height:70
(

fn testcallback =
(
DotNetTimeCallback.framelbl.text = "Current Frame - " + currenttime as string
)

button btnaddCB"Add Callback" pos:[3,3] width:92 height:40
button btnremoveCB "Remove Callback" pos:[99,3] width:92 height:40
dotnetcontrol framelbl "label" pos:[4,46] width:186 height:21

on DotNetTimeCallback open do
(
framelbl.borderstyle = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
framelbl.backcolor = (dotnetclass "System.Drawing.Color").slategray
framelbl.forecolor = (dotnetclass "System.Drawing.Color").black
framelbl.textalign = (dotnetclass "System.Drawing.ContentAlignment").middlecenter
framelbl.text = "Current Frame - " + currenttime as string
)

on btnaddCB pressed do
(
if DotNetTimeChangeCallback == undefined do
(
DotNetTimeChangeCallback= dotnetobject "ManagedServices.AnimationFrameChangeListener"
dotNet.addEventHandler DotNetTimeChangeCallback "AnimationFrameChanged" testcallback
framelbl.backcolor = (dotnetclass "System.Drawing.Color").orangered
framelbl.forecolor = (dotnetclass "System.Drawing.Color").yellow
)

)
on btnremoveCB pressed do
(
try
(
dotNet.removeEventHandler DotNetTimeChangeCallback "AnimationFrameChanged" testcallback
DotNetTimeChangeCallback.dispose()
DotNetTimeChangeCallback = nothing
framelbl.backcolor = (dotnetclass "System.Drawing.Color").slategray
framelbl.forecolor = (dotnetclass "System.Drawing.Color").black
)
catch()

)

)
createdialog DotNetTimeCallback
404