Perhaps this will work better for you:
Code: Select all_NoEcho
_-RunScript (
Sub Maxwell_Bongo2SunStudy()
Set mw = CreateObject("Maxwell.Script.ScriptObject")
' scene options
mw.Environment.SunEnabled = True
mw.Environment.EnvironmentType = "PhysicalSky"
mw.PluginOptions.CacheMXSMeshes = True
' animation options
startTime = 9.5 ' start @ 09:30
endTime = 12.5 ' end @ 12:30
startFrame = 0 ' start @ frame 0
frameCount = 180 ' 1 minute per frame
' optionally, get options using the command prompt
promptForValues = false
if promptForValues Then
startTime = Rhino.GetReal("Enter Start Time", 9.5, 0.0)
if IsNull(startTime) Then Exit Sub ' cancelled
endTime = Rhino.GetReal("Enter End Time", 12.5, startTime)
if IsNull(endTime) Then Exit Sub ' cancelled
startFrame = Rhino.GetInteger("Enter Start Frame", 0, 0)
if Isnull(startFrame) Then Exit Sub ' cancelled
frameCount = Rhino.GetInteger("Enter Frame Count", 180, startFrame)
if IsNull(frameCount) Then Exit Sub ' cancelled
End If
' internal variables
timeSpan = endTime - startTime
increment = timeSpan / frameCount
currentTime = startTime
endFrame = startFrame + frameCount - 1
currentFrame = startFrame
frameDuration = increment * 60.0
cmdPrefix = "_ClearUndo _BongoSetCurrentTick "
' abort if frame length is less than 1 minute
If frameDuration < 1.0 Then
Rhino.Print("Too many frames: minimum time per frame is 1 minute.")
Exit Sub
End If
' optionally, ensure timeline range is sufficient
setTimelineRange = true
If setTimelineRange Then
rangeCmd = "-_BongoSetTimelineDisplayRange"
rangeCmd = rangeCmd & " Start=" & startFrame
rangeCmd = rangeCmd & " Stop=" & endFrame + 1
rangeCmd = rangeCmd & " _Enter"
Rhino.Command rangeCmd, false
End If
' export the animation
Rhino.Print("Maxwell_Bongo2SunStudy info:")
Rhino.Print(" - time span: " & startTime & "-" & endTime)
Rhino.Print(" - frame range: " & startFrame & "-" & endFrame)
Rhino.Print(" - frame time: " & frameDuration & " min.")
Rhino.Print("Exporting animation...")
mw.Rendering.BeginAnimation()
While currentTime <= endTime
Rhino.Command cmdPrefix & currentFrame, false
mw.DateAndTime.TimeOfDay = currentTime
mw.Rendering.RenderToMxs()
currentFrame = currentFrame + 1
currentTime = currentTime + increment
Wend
mw.Rendering.EndAnimation()
Rhino.Print("Animation export done.")
End Sub
Call Maxwell_Bongo2SunStudy()
)
The plugin's
TimeOfDay value is in fractional hours (e.g. 9.5 = 9:30), but underneath, Maxwell's time resolution is in minutes, not seconds, so if you try to export more than 60 frames for a given hour, some frames will end up being the same. This script will fail with an error if you use it to set up such an animation.
This script also has a couple of options that you can set to true/false to determine how you want it to behave: the first just lets you decide whether you want it to get options from the command line, and the second makes sure that the timeline range is sufficient (Bongo will stop with an error if you try to animate beyond the end). To ensure that you can't get into an infinite loop, it uses a temporary
currentTime variable, rather than reading the current
TimeOfDay value (it is not guaranteed to get out what you put in, since there is error-checking involved). It also gets rid of the Option Explicit and various error checks, just to make things more readable.
So give that a try and let me know what you think.