Simulation range and time

Share your scripts with other members
Lukich
Posts: 14
Joined: Thu Apr 05, 2007 6:30 am

Simulation range and time

Postby Lukich » Thu Oct 04, 2007 7:39 pm

# Name: Simulation range and time
# Description: a little script that allows you to specify a range of frames you want to simulate and shows you
# the time it took to simulate it in hours, minutes and seconds. Just run it as a batch script or install like
# you would a regular script. If you think of something that can be added to this script, please let me know at
# Lukich@gmail.com. Thanks!
# Author: Luka Stolyarov
# Date: October 4, 2008
# Version 1.0



import time
simstop = GUIFormDialog.new()
simstop.addIntField("1.Min",0)
simstop.addIntField("2.Max",200)
if simstop.show() == (GUI_DIALOG_ACCEPTED):
showtime_start = time.localtime()
start_hr = showtime_start[3]
start_min = showtime_start[4]
start_sec = showtime_start[5]
min = simstop.getFieldValue("1.Min")
max = simstop.getFieldValue("2.Max")
scene.simulate( min,max )
current_frame = scene.getCurrentFrame()
if current_frame == max:
showtime_end = time.localtime()
end_hr = showtime_end[3]
end_min = showtime_end[4]
end_sec = showtime_end[5]
fin_hr = end_hr - start_hr
fin_min = end_min - start_min
fin_sec = end_sec - start_sec
scene.message(str(fin_hr)+" hr "+str(fin_min)+" min "+str(fin_sec)+" sec")


shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Simulation range and time

Postby shaun_michael » Thu Oct 04, 2007 8:01 pm

Hi Luka,

As you know python is rather fond of proper indentation in its scripts so I hope you dont mind if I repost your script with the correct tabbing.

Code: Select all

import time
simstop = GUIFormDialog.new()
simstop.addIntField("1.Min",0)
simstop.addIntField("2.Max",200)
if simstop.show() == (GUI_DIALOG_ACCEPTED):
   showtime_start = time.localtime()
   start_hr = showtime_start[3]
   start_min  = showtime_start[4]
   start_sec = showtime_start[5]
   min = simstop.getFieldValue("1.Min")
   max = simstop.getFieldValue("2.Max")
   scene.simulate( min,max )
   current_frame = scene.getCurrentFrame()
   if current_frame == max:
      showtime_end = time.localtime()
      end_hr = showtime_end[3]
      end_min = showtime_end[4]
      end_sec = showtime_end[5]
      fin_hr = end_hr - start_hr
      fin_min = end_min - start_min
      fin_sec = end_sec - start_sec
      scene.message(str(fin_hr)+" hr "+str(fin_min)+" min "+str(fin_sec)+" sec")

Incidentally, I think its important to remind people that you can not magically skip frames in a simulation. In other words if you haven't simulated any frames before running this script, and you enter 50 - 150 as your range, your simulation will effectively start from new at frame 50. In other words, RF wont magiaclly instantly calculate the first 50 frames and then start simulating the 51st frame using frame 49's data (as it doesn't exist). :)

Imagine if it did though - you'd be a hero.

Thanks for sharing your script Luka.

Shaun

Lukich
Posts: 14
Joined: Thu Apr 05, 2007 6:30 am

Simulation range and time

Postby Lukich » Fri Oct 05, 2007 2:40 am

That's true :) I wish it were so easy. Thanks for reformatting the script. What's the proper way, by the way. Do I use "Insert block of code" option?

shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Simulation range and time

Postby shaun_michael » Fri Oct 05, 2007 5:42 am

Code: Select all

Insert block of code

Yes please. It should help those who aren't so familiar with python scripting to cut and paste and be up-and-running much easier.

Cheers Luka.

Shaun


Return to “User Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests