win = Windows()
author = '(C) IDSLK / NateLiqGrav'
scriptversion = 0.20230820
scriptversiontext = str(scriptversion)
scriptname = 'Motion in Assembly + Capture '
message = 'Script is not suitable for running in parts!'
error = 'Error! '
outputfolder = ''
snapname = ''
saving = False
reso = 0
resolutionlist = ['800*600','1024*768','1920*1080']
resolutions = [[800,600],[1024,768],[1920,1080]]
parametername = 'A2' # parametername from formeleditor which is will be used for animation
M = -1 # will be used if parameter check failes / (parameter is not available in parameterset)
steps = 10 #number of animation steps
try:
co = CurrentAssembly()
print 'Running in Assembly: ',co
AD_co = co._Assembly #This gets the API version of the assembly
except:
co = CurrentPart()
print 'Running in Part',co
win.InfoDialog(message,scriptname)
sys.exit()
# called when an input changes in the dialog window
def input_changed(index, value):
if index == 0 and value == False:
print 'off'
win.DisableInput(1)
win.DisableInput(2)
win.DisableInput(3)
elif index == 0 and value == True:
print 'on'
win.EnableInput(1)
win.EnableInput(2)
win.EnableInput(3)
pass
# called when user confirms selections
def selection_made():
win.DisableInput(1)
win.DisableInput(2)
win.DisableInput(3)
pass
def SaveLocation():
options = []
options.append(['Set checkmark for saving snapshots', WindowsInputTypes.Boolean, False]) # 0
options.append(['please choose the directory for the snapshots', WindowsInputTypes.Folder, 'C:\Users\Default\Desktop']) # 1
options.append(['please enter a name for the snapshots', WindowsInputTypes.String, co.Name]) # 2
options.append(['please choose the resolution for the snapshots', WindowsInputTypes.StringList, resolutionlist]) # 3
options.append(['please enter a number of animation steps', WindowsInputTypes.Integer, steps]) # 4
values = win.OptionsDialog(author+scriptname+scriptversiontext, options,230, input_changed, selection_made)
if values == None:
sys.exit('User canceled')
# or return OutputFolder
global outputfolder,snapname,reso,steps,saving
outputfolder = values[1]
snapname = values[2]
reso = values[3]
steps = values[4]
saving = values[0]
#main-------------------
SaveLocation()
for i in range(len(co.Parameters)):
if co.Parameters[i].Name == parametername:
M = i
print 'actual internal parameter number: ', M
if M == -1:
text = 'No Parameter with name'+parametername+' has been found! Script will be terminated...'
win.InfoDialog(text,scriptname)
print 'No Parameter with name',parametername,' has been found! Script will be terminated...'
sys.exit()
Posi_x = co.Parameters[M].Value
print 'actual parameter value: ',Posi_x
print 'animating...'
first = 1
from System.Diagnostics import Stopwatch
from System import TimeSpan
watch = Stopwatch.StartNew()
for r in range(steps):
Posi_x = Posi_x - 1
co.Parameters[M].Value = Posi_x
#co.Regenerate()
AD_co.RegenerateDesign(0) #This does a basic regen using the API version of the assembly
if first:
first = 0
watch.Stop()
ts = watch.Elapsed
total_ts = TimeSpan.FromTicks(ts.Ticks * float(steps))
print 'Estimated time: ' + str(total_ts.Hours) + ' Hours, ' + str(total_ts.Minutes) + ' Minutes, and ' + str(total_ts.Seconds) + ' Seconds.'
value = win.QuestionDialog('It took ' + str(ts.Seconds) + ' Seconds for the first movement.\nEstimated time to finish is ' + str(total_ts.Hours) + ' Hours, ' + str(total_ts.Minutes) + ' Minutes, and ' + str(total_ts.Seconds) + ' Seconds to complete ' + str(steps) + ' Steps\nAre you sure you want to continue?' , 'Are you sure you want to continue?')
if not value:
sys.exit()
else:
watch.Restart()
if saving == True:
co.SaveSnapshot(outputfolder+'\_'+snapname+str(r)+'.bmp',resolutions[reso][0],resolutions[reso][1],0,0)
watch.Stop()
final_ts = ts.Add(watch.Elapsed)
print 'Final time: ' + str(final_ts.Hours) + ' Hours, ' + str(final_ts.Minutes) + ' Minutes, and ' + str(final_ts.Seconds) + ' Seconds.'
if saving == True:
infotext = 'Pictures saved in folder: '+outputfolder
print infotext
win.InfoDialog(infotext,scriptname)
print 'done :-)'