[Closed] DayLightSystem
Hi there,
Yesterday, I was having some problems with the daylightSystem and I did a small search in the forum and I realized that this was a common problem to others too. I’ve also found that the SDK exposes the parameters I wanted (date and time) in way better format (Point3 and not float). Since I don’t know to develop in C++ and since that would also be an overkill since I only wanted to get those two parameters I decided to approach it with DotNet. After a couple of hours I found how to do it and I thought to share the code just in case some else in the future, has the same problem.
Getting the IDaylightSystem2 Interface
--Get the global interface
iGlobal = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
--Get the node
myNode = iGlobal.COREInterface.GetINodeByHandle $Daylight001.inode.handle
--Can't find a way to to create the "Autodesk.Max.Wrappers.Interface_ID" dotNetObject
--so I'm taking it from the "IDaylightSystemFactory" and I then I'm changing the id.
--I found the two parts in an SDK sample.
IId = iGlobal.IDaylightSystemFactory.instance.id
IId.PartA = 537083807
IId.PartB = 111563888
--Get the interface
IDaylightSystem2 = myNode.ObjectRef.GetInterface IId
IDaylightSystem2 Properties
show IDaylightSystem2
.AcquireInterface : <Autodesk.Max.IBaseInterface>, read-only
.ActionTable : <Autodesk.Max.IActionTable>, read-only
.CompassDiameter : <System.Single>
.Date : <Autodesk.Max.IPoint3>
.DaylightControlType : <Autodesk.Max.IDaylightSystem2.DaylightControlType>
.DaylightSavingTime : <System.Boolean>
.Desc : <Autodesk.Max.IFPInterfaceDesc>, read-only
.Id : <Autodesk.Max.IInterface_ID>, read-only
.Implementation : <System.Object>, read-only
.INativeObject__Handle : <System.IntPtr>, read-only
.Latitude : <System.Single>, read-only
.LifetimeControl : <Autodesk.Max.BaseInterface.LifetimeType>, read-only
.Location : <System.String>, read-only
.Longitude : <System.Single>, read-only
.NorthDirection : <System.Single>
.OrbitalScale : <System.Single>
.Position : <Autodesk.Max.IPoint3>
.Sky : <Autodesk.Max.ILightObject>, read-only
.Sun : <Autodesk.Max.ILightObject>, read-only
.TimeOfDay : <Autodesk.Max.IPoint3>
.WeatherFile : <Autodesk.Max.MaxSDK.AssetManagement.IAssetUser>
true
Example for changing parameters
IDaylightSystem2.Date.x = 2 --Month
IDaylightSystem2.Date.y = 10 --Day
IDaylightSystem2.Date.z = 2014 --Year
Hope that was helpful.
Cheers,
Nick
what was wrong with using GetWeatherFileSpecificTimeAndDate? it returns timeOfDay and date in desired format (point3).
edited… i see now. it’s for manual setup… ignore my question.
Hey great – thanks !
I did the same a year ago or so – building on the daylightsystem plugin’s sample code and making a special build of the plugin which exposes those paramteres
Your method is of course better, more flexible and does’nt require any plugin swapping !
BTW: i think to remember that there is a bug when using the “controlmode” in the daylightsystem’s MXS exposure. I fixed that in my custom build version too …
Hey Spacefrog,
I’m glad that you liked my approach. I haven’t tried yet anything else other than .Date and .TimeOfDay but since I’m using the dotNet wrapper and not the MaxScript interface, I assume that the “controlmode” will work fine (even though I have no clue what this “controlmode” is )?!
I don’t remember the exact facts what was broken, but “controlmode” corresponds to the radiobutton group in the daylight system’s control parameters, where you set the sun positioning options: “manual”, “date/time/location” or “weather data file” …
Some of the options did’nt work when set through maxscript, but as i said, i don’T remember what exactly
yep, no worries. Personally (at least at the moment) I only need to access the date and the TimeOfDay, so it works fine for me.
Thanks, for your comments though.
I suppose this method needs a file, otherwise it seems to return the defaults.
I created a system with the 12h 0h 0s and 6m 21d 2014y and I run this code
aTime = point3 0 0 0
aDate = point3 0 0 0
$Daylight001.GetWeatherFileSpecificTimeAndDate &aTime &aDate
[/]
I got the following results
[12,0,0]
[1,1,2007]
edit: question ignored as requested :scream: