-
Notifications
You must be signed in to change notification settings - Fork 4
/
BatchCameraRender-functions-misc.ms
1646 lines (1472 loc) · 57.8 KB
/
BatchCameraRender-functions-misc.ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--########################--
--FUNCTIONS for batch camera render script
--########################--
--
fn CompileDotNet src =
(
local csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
local compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.AddRange #("System.dll", "System.Windows.Forms.dll")
compilerParams.GenerateInMemory = true
local compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(src)
if (compilerResults.Errors.Count > 0 ) then
(
local errs = stringstream ""
for i = 0 to (compilerResults.Errors.Count-1) do
(
err = compilerResults.Errors.Item[i]
format "Error:% Line:% Column:% %\n" err.ErrorNumber err.Line err.Column err.ErrorText to:errs
)
format "Errors encountered while compiling C# code\n" errs
format "%\n" errs
)
)
fn CreateNativeWindowOps =
(
local source ="
using System;
using System.Windows.Forms;
public class WindowHook : NativeWindow
{
private const int WM_COMMAND = 0x0111;
public event EventHandler WmCommand;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_COMMAND:
this.ReleaseHandle();
if (this.WmCommand != null) this.WmCommand(this, EventArgs.Empty);
break;
}
base.WndProc(ref m);
}
}
"
CompileDotNet source
)
fn CreatePostNotifier =
(
local source = "
using System;
using System.Windows.Forms;
using System.Threading;
public class PostNotifier
{
public event EventHandler PostEvent;
public void PostNotify() {
SynchronizationContext.Current.Post(delegate(object x) { if (this.PostEvent != null) this.PostEvent(this, EventArgs.Empty); }, null);
//SynchronizationContext.Current.Post(delegate(object x) { Application.RaiseIdle(EventArgs.Empty); }, null);
}
}"
CompileDotNet source
)
isVrayRenderer
fn shouldBeSaved =
(
local result = false
if (isVrayRenderer()) then
result = (not batchCamPreview) and (Render_Output_Rollout.save_file.checked or Vray_Settings_Rollout.save_vray_image_file.checked)
else
result = (not batchCamPreview) and (Render_Output_Rollout.save_file.checked)
result
)
--function adds subitem to list item and makes it style active or inactive
fn add_sub_item listItem subitem_value subitem_name active_state =
(
sub_item = undefined
if active_state then
(
sub_item = listItem.SubItems.add (subitem_value as string)
sub_item.ForeColor = sub_item.ForeColor.Black
sub_item.Font = dotnetobject "System.Drawing.Font" sub_item.Font (dotnetclass "System.Drawing.FontStyle").Regular
)
else
(
sub_item = listItem.SubItems.add ("undefined")
sub_item.ForeColor = sub_item.ForeColor.LightGray
sub_item.Font = dotnetobject "System.Drawing.Font" sub_item.Font (dotnetclass "System.Drawing.FontStyle").Italic
)
sub_item.name = subitem_name
)
fn set_sub_item listItem subitem_value subitem_name=
(
sub_item = listItem.SubItems.Item subitem_name
sub_item.text = subitem_value
sub_item.ForeColor = sub_item.ForeColor.Black
sub_item.Font = dotnetobject "System.Drawing.Font" sub_item.Font (dotnetclass "System.Drawing.FontStyle").Regular
)
fn clear_sub_item listItem subitem_name=
(
sub_item = listItem.SubItems.Item subitem_name
sub_item.text = "undefined"
sub_item.ForeColor = sub_item.ForeColor.LightGray
sub_item.Font = dotnetobject "System.Drawing.Font" sub_item.Font (dotnetclass "System.Drawing.FontStyle").Italic
)
fn get_camera_list =
(
local camera_array = #()
local camera_list = for obj in cameras where iskindof obj camera collect obj
local xcount = xrefs.getXRefFileCount()
local xref_cameras = #()
for xindex = 1 to xcount do
(
xscene = xrefs.getXRefFile xindex
local x_cameras = for obj in xscene.tree.children where iskindof obj camera collect obj
join xref_cameras x_cameras
)
for cam in camera_list do
(
append camera_array cam
for attr in cam.baseobject.custattributes do
(
if attr.name == "BatchCamAttr" then
append camera_array (attr)
)
)
join camera_array xref_cameras
camera_array
)
fn trimLeadTrailSpaces path_string =
(
path_string = trimRight path_string " "
path_string = trimLeft path_string " "
path_string
)
fn isNotUndefinedOrEmpty var =
(
result = true
if var == undefined then
result = false
else if (trimleft (var as string) " ") == "" then
result = false
result
)
fn isNotUndefined var =
(
result = true
if var != undefined and var != "undefined" and var != "" then
-- if (isNotUndefinedOrEmpty var) and var != "undefined" then
result = true
else
result = false
result
)
fn isUndefined var =
(
result = true
if var == undefined or var == "undefined" or var == "" then
-- if (not isNotUndefinedOrEmpty var) or var == "undefined" then
result = true
else
result = false
result
)
fn get_render_preset_array =
(
render_preset_array = #()
if (maxVersion())[1] >= 11000 then --run renderPresetMRUList command only if script is running under 3dsmax 2009+
render_preset_array = for i in renderPresetMRUList where (i[1]!="") collect i[1]
sort render_preset_array
render_preset_array
)
fn get_scene_state_array =
(
scenestate_count = sceneStateMgr.GetCount()
scenestate_array = for i=1 to scenestate_count collect ((sceneStateMgr.GetSceneState i) as string)
sort scenestate_array
scenestate_array
)
fn get_state_sets_array =
(
local stateSetsDotNetObject = dotNetObject "Autodesk.Max.StateSets.Plugin"
local stateSets = stateSetsDotNetObject.Instance
local masterState = stateSets.EntityManager.RootEntity.MasterStateSet
local statesList = dotnetobject "System.Collections.Generic.List`1[[Autodesk.Max.StateSets.Entities.StateSets.StateSet, Autodesk.Max.StateSets, Version=19.51.835.0, Culture=neutral, PublicKeyToken=null]]"
masterState.CollectDescendantStateSets statesList
local scenestate_count = masterState.DescendantStateCount
local scenestate_array = for i=1 to scenestate_count where not (statesList.item[i-1].IsObjectStateSet) collect ((statesList.item[i-1].Name) as string)
sort scenestate_array
scenestate_array
)
struct BatchCameraRenderParamsStruct
(
BatchCameraRender_frames,
BatchCameraRender_framerange_from,
BatchCameraRender_framerange_to,
BatchCameraRender_anim_frame_range,
BatchCameraRender_frame_width,
BatchCameraRender_frame_heigth,
BatchCameraRender_render_output,
BatchCameraRender_elements_state,
BatchCameraRender_not_save_elements,
BatchCameraRender_elements_output,
BatchCameraRender_solo_lights,
BatchCameraRender_on_lights,
BatchCameraRender_off_lights,
BatchCameraRender_scene_state,
BatchCameraRender_render_preset,
BatchCameraRender_irmap_mode,
BatchCameraRender_auto_save_irmap,
BatchCameraRender_auto_switch_irmap,
BatchCameraRender_irmap_read_file,
BatchCameraRender_irmap_save_file,
BatchCameraRender_lcmap_mode,
BatchCameraRender_auto_save_lcmap,
BatchCameraRender_auto_switch_lcmap,
BatchCameraRender_lcmap_read_file,
BatchCameraRender_lcmap_save_file,
BatchCameraRender_prerender_script,
BatchCameraRender_prerender_enabled,
BatchCameraRender_postrender_script,
BatchCameraRender_postrender_enabled,
BatchCameraRender_image_aspect,
BatchCameraRender_region_enabled,
BatchCameraRender_region_x,
BatchCameraRender_region_y,
BatchCameraRender_region_w,
BatchCameraRender_region_h,
BatchCameraRender_perCameraScriptEnable,
BatchCameraRender_perCameraScript
)
--function to save variable to ini file
fn saveVar2IniFile section_name var_name var_value local_path: =
(
INIFileDir = ""
if (local_path != unsupplied) then
INIFileDir = local_path
else
INIFileDir = ((getdir #plugcfg) + "\\BatchCameraRender\\")
if (getDirectories INIFileDir).count == 0 then makeDir INIFileDir
INIFilename = pathConfig.appendPath INIFileDir "BatchCameraRender.ini"
setINISetting INIFilename section_name var_name (var_value as string)
)
--function to load variable to ini file
fn loadVarFromIniFile section_name var_name local_path: =
(
INIFileDir = ""
if (local_path == unsupplied) then
INIFileDir = ((getdir #plugcfg) + "\\BatchCameraRender\\")
else
INIFileDir = local_path
INIFilename = pathConfig.appendPath INIFileDir "BatchCameraRender.ini"
temp_value = getINISetting INIFilename section_name var_name
if temp_value == "" then undefined else temp_value
)
fn propName2Id property_name =
(
property_id = 0
case property_name of
(
"BatchCameraRender_frames": property_id = 7801
"BatchCameraRender_framerange_from": property_id = 7802
"BatchCameraRender_framerange_to": property_id = 7803
"BatchCameraRender_anim_frame_range": property_id = 7804
"BatchCameraRender_frame_width": property_id = 7805
"BatchCameraRender_frame_heigth": property_id = 7806
"BatchCameraRender_render_output": property_id = 7807
"BatchCameraRender_elements_state": property_id = 7808
"BatchCameraRender_not_save_elements": property_id = 78081
"BatchCameraRender_elements_output": property_id = 7809
"BatchCameraRender_solo_lights": property_id = 7810
"BatchCameraRender_on_lights": property_id = 7811
"BatchCameraRender_off_lights": property_id = 7812
"BatchCameraRender_scene_state": property_id = 7813
"BatchCameraRender_render_preset": property_id = 7814
"BatchCameraRender_irmap_mode": property_id = 7815
"BatchCameraRender_auto_save_irmap": property_id = 7816
"BatchCameraRender_auto_switch_irmap": property_id = 7817
"BatchCameraRender_irmap_read_file": property_id = 7818
"BatchCameraRender_irmap_save_file": property_id = 7819
"BatchCameraRender_lcmap_mode": property_id = 7820
"BatchCameraRender_auto_save_lcmap": property_id = 7821
"BatchCameraRender_auto_switch_lcmap": property_id = 7822
"BatchCameraRender_lcmap_read_file": property_id = 7823
"BatchCameraRender_lcmap_save_file": property_id = 7824
"BatchCameraRender_prerender_script": property_id = 7825
"BatchCameraRender_prerender_enabled": property_id = 7826
"BatchCameraRender_postrender_script": property_id = 7827
"BatchCameraRender_postrender_enabled": property_id = 7828
"BatchCameraRender_image_aspect": property_id = 7829
"BatchCameraRender_UserKey1": property_id = 7830
"BatchCameraRender_UserKey2": property_id = 7831
"BatchCameraRender_UserKey3": property_id = 7832
"BatchCameraRender_UserVal1": property_id = 7833
"BatchCameraRender_UserVal2": property_id = 7834
"BatchCameraRender_UserVal3": property_id = 7835
"BatchCameraRender_bbJobName": property_id = 7836
"BatchCameraRender_elementName": property_id = 7837
"BatchCameraRender_OnSubmitScriptEnable": property_id = 7838
"BatchCameraRender_OnSubmitScript": property_id = 7839
"BatchCameraRender_perCameraScriptEnable": property_id = 7840
"BatchCameraRender_perCameraScript": property_id = 7841
"BatchCameraRender_lastRenderPath": property_id = 7842
"BatchCameraRender_vray_ortho_mode": property_id = 7844
"BatchCameraRender_item_index": property_id = 7845
"BatchCameraRender_region_enabled": property_id = 7846
"BatchCameraRender_region_x": property_id = 7847
"BatchCameraRender_region_y": property_id = 7848
"BatchCameraRender_region_w": property_id = 7849
"BatchCameraRender_region_h": property_id = 7850
"BatchCameraRender_state_set": property_id = 7851
)
property_id
)
-- setUserProp function wrapper to set dirty flag everytime user properties are affected by script
fn setUserProperty list_item property_name property_value=
(
-- format "obj_itself:% property_name:% property_value:%\n" obj_itself property_name property_value
setAppData (list_item.tag.value) (propName2Id property_name) (property_value as string)
setSaveRequired true --set dirt flag after setting each user property
)
--temporary helper functions
--used to correctly assign default values
fn getUserPropertyFromObject obj_itself property_name=
(
property_value = getAppData obj_itself (propName2Id property_name)
property_value
)
fn isFrameRangeProperty property_name=
(
if ((property_name == "BatchCameraRender_frames") or (property_name == "BatchCameraRender_framerange_from") or \
(property_name == "BatchCameraRender_framerange_to") or (property_name == "BatchCameraRender_anim_frame_range")) then true else false
)
fn isFrameRangeUndefined camera_object=
(
temp_string1 = getUserPropertyFromObject camera_object "BatchCameraRender_frames"
temp_string2 = getUserPropertyFromObject camera_object "BatchCameraRender_framerange_from"
temp_string3 = getUserPropertyFromObject camera_object "BatchCameraRender_framerange_to"
temp_string5 = getUserPropertyFromObject camera_object "BatchCameraRender_anim_frame_range"
if (isUndefined temp_string1) and (isUndefined temp_string2) and (isUndefined temp_string3) and (isUndefined temp_string5) then true else false
)
--endof temp functions. will remove them in version 2.x
fn setRootNodeData property_name property_value =
(
if (isNotUndefinedOrEmpty (property_value as string)) then
setAppData rootNode (propName2Id property_name) (property_value as string)
else
setAppData rootNode (propName2Id property_name) ""
setSaveRequired true --set dirt flag after setting each user property
)
fn getRootNodeData property_name =
(
data_string = ""
data_string = batchCameraRender_getUserProperty rootNode property_name --user standard function to add default settings ability to rootnode data
data_string
)
fn getCameraFromCA ca_obj =
(
local cam_obj = undefined
if (superclassof ca_obj == AttributeDef) then
(
local base_obj = custattributes.getowner ca_obj
local dep_objs = refs.dependentNodes base_obj
if (dep_objs.count > 0) then
(
local temp_cam = dep_objs[1]
if (superclassof temp_cam == camera) then
cam_obj = temp_cam
)
)
else
(
cam_obj = ca_obj
)
cam_obj
)
fn getPresetName preset_obj =
(
local result_name = undefined
if (superclassof preset_obj == camera) then
(
result_name = preset_obj.name
)
else
(
local cam_obj = getCameraFromCA preset_obj
local preset_index = 0
local found_obj = undefined
for obj in cam_obj.baseobject.custattributes while found_obj == undefined do
(
preset_index += 1
local num_str = formattedPrint preset_index format:"03d"
if (obj == preset_obj) then
(
result_name = cam_obj.name + "_preset_" + num_str
)
)
)
result_name
)
--parser function
--replaces special keywords in string with values from argument dictionary
--dictionary syntax is (keyword, value)
--sample dictionary:
/* param_dictionary = #(
#("cameraname", "CAMERANAME"),
#("scenestate", "SCENESTATE"),
#("resolution", "RESOLUTION"),
#("date", "DATE"),
#("var:varname", "VARNAME"),
#("scenename", "SCENENAME")
#("projectfolder", "PROJECTNAME")
) */
fn do_modify in_string replace_start replace_end replace_text=
(
keyword = (substring in_string replace_start replace_end)
-- format "keyword: %\n" keyword
if keyword == "%up%" then
(
--handle %up% keyword
--remove leaf from the path to point it to upper folder
currentPath = substring in_string 1 (replace_start - 1)
-- format "currentPath: %\n" currentPath
if ((pathConfig.isLegalPath currentPath) and (not (pathConfig.isRootPath currentPath))) do
currentPath = pathConfig.removePathLeaf currentPath --replace old path with new, truncated one.
in_string = currentPath + (substring in_string (replace_start + keyword.count) -1)
-- format "in_string: %, currentPath: %\n" in_string currentPath
)
else
(
-- format "in_string: %, replace_text: %\n" in_string replace_text
in_string = replace in_string replace_start replace_end replace_text --replace keyword with word from dictionary
)
in_string
)
fn parse_file_name_template input_string dictionary =
(
found_count = 0
found_any = false
result_substring = input_string
i_emergency = 0 --emergency counter - some sort of emergency stop in case of infinite loop :)
do
(
i_emergency += 1
keyword_start = findString result_substring "%" --search for start of the keyword
if keyword_start != undefined then
(
keyword_substring = substring result_substring (keyword_start+1) -1 -- remaining of the string possibly with keyword
keyword_end = findString keyword_substring "%" --search for end of the keyword
found_any = true
found_count += 1
if keyword_end != undefined then
(
found_count += 1
keyword = substring keyword_substring 1 (keyword_end-1) --exclude the keyword - since we using substring here, keyword is always as start of the string
-- format "keyword: %\n" keyword
--replace keyword with actual value
--get keywords and values from argument dictionary
was_found = false --this flag remains false if none of the dictionary keywords would not equal to template keyword
for i=1 to dictionary.count do
(
if keyword == dictionary[i][1] then
(
was_found = true --set flag to true if keyword is found
-- format "string: %, keyword: % \n" result_substring dictionary[i][2]
result_substring = do_modify result_substring keyword_start (keyword_end+1) dictionary[i][2] --replace keyword with word from dictionary
)
)
if not was_found then --if flag is not raised then replace quoted keyword with unquoted keyword
(
result_substring = replace result_substring keyword_start (keyword_end+1) keyword
)
)
else
(
found_any = false --exit loop if end of keyword not found
-- here delete trailing %-char
--add template error warning
)
)
else
(
found_any = false
)
-- format "i_emergency: %\n" i_emergency
)
while (found_any and not i_emergency > 100 ) --proceed with the loop until start or end are found
--or more then 100 "%" characters found
-- print result_substring
result_substring
)
fn exec_user_val userValue=
(
result = ""
try
(
if userValue[1] == "@" then
result = substring userValue 2 (userValue.count-1)
else
result = execute (userValue as string)
)
catch
(
result = "ErrUserVal"
)
(result as string)
)
fn compose_user_dictionary =
(
parsing_dictionary = #()
--user-defined keywords
userKeyword = getRootNodeData "BatchCameraRender_UserKey1"-- getAppData rootnode (propName2Id "BatchCameraRender_UserKey1")
userValue = getRootNodeData "BatchCameraRender_UserVal1" --getAppData rootnode (propName2Id "BatchCameraRender_UserKey1")
if isNotUndefinedOrEmpty userKeyword then
append parsing_dictionary #( (userKeyword as string), (exec_user_val userValue) )
userKeyword = getRootNodeData "BatchCameraRender_UserKey2"-- getAppData rootnode (propName2Id "BatchCameraRender_UserKey1")
userValue = getRootNodeData "BatchCameraRender_UserVal2" --getAppData rootnode (propName2Id "BatchCameraRender_UserKey1")
if isNotUndefinedOrEmpty userKeyword then
append parsing_dictionary #( (userKeyword as string), (exec_user_val userValue) )
userKeyword = getRootNodeData "BatchCameraRender_UserKey3"-- getAppData rootnode (propName2Id "BatchCameraRender_UserKey1")
userValue = getRootNodeData "BatchCameraRender_UserVal3" --getAppData rootnode (propName2Id "BatchCameraRender_UserKey1")
if isNotUndefinedOrEmpty userKeyword then
append parsing_dictionary #( (userKeyword as string), (exec_user_val userValue) )
parsing_dictionary
)
--function to compute global keywords, not realting to any camera object
fn compose_global_dictionary =
(
local parsing_dictionary = #()
--date keyword
dateClass = (dotnetclass "System.DateTime").Now
date_string = dateClass.ToString("yyyy-MM-dd")
append parsing_dictionary #("date", date_string)
--scenename keyword
scenename_string = getFilenameFile maxFileName
append parsing_dictionary #("scenename", scenename_string)
--project name keyword
projectfolder_string = pathConfig.getCurrentProjectFolder()
append parsing_dictionary #("projectfolder", projectfolder_string)
append parsing_dictionary #("projectpath", projectfolder_string)
local projectname_string = pathConfig.getCurrentProjectFolder()
if (doesFileExist projectname_string) then
projectname_string = pathConfig.stripPathToLeaf projectname_string
append parsing_dictionary #("projectname", projectname_string)
-- scene path keyword
scenepath_string = maxFilePath
scenepath_string = substring scenepath_string 1 (scenepath_string.count-1)
append parsing_dictionary #("scenefolder", scenepath_string)
append parsing_dictionary #("scenepath", scenepath_string)
append parsing_dictionary #("up", "") --added to dictionary just to have parsing function call do_modify method - this keyword handling happens there.
append parsing_dictionary #("trynum", (Net_Render_Options_Rollout.Try_Counter.value) as string)
parsing_dictionary
)
--function to compute camera-related keywords
fn compose_parsing_dictionary camera_obj extraItems: =
(
--compose parsing dictionary for given camera
local parsing_dictionary = #()
join parsing_dictionary (compose_global_dictionary())
join parsing_dictionary (compose_user_dictionary())
--append extra items first. they should not be the same as the ones computed in this function
if extraItems != unsupplied then
(
if (classof extraItems) == Array then
(
for item in extraItems do
append parsing_dictionary item
)
)
--camername keyword
local preset_name = getPresetName camera_obj
append parsing_dictionary #("presetname", preset_name)
local cam_obj = getCameraFromCA camera_obj
append parsing_dictionary #("cameraname", ((cam_obj.name) as string))
--scenestate keyword
append parsing_dictionary #("scenestate", ((batchCameraRender_getUserProperty camera_obj "BatchCameraRender_scene_state") as string))
--state_sets
append parsing_dictionary #("stateset", ((batchCameraRender_getUserProperty camera_obj "BatchCameraRender_state_set") as string))
--renderpreset keyword
append parsing_dictionary #("renderpreset", ((batchCameraRender_getUserProperty camera_obj "BatchCameraRender_render_preset") as string))
--resolution keyword
xres_prop = batchCameraRender_getUserProperty camera_obj "BatchCameraRender_frame_width"
yres_prop = batchCameraRender_getUserProperty camera_obj "BatchCameraRender_frame_heigth"
resolution_string = (xres_prop as string + "x" + yres_prop as string )
append parsing_dictionary #("resolution", resolution_string)
-- print parsing_dictionary
parsing_dictionary
)
--function to compute camera-related keywords. Computes render output. Should not be used in output path properties.
fn compose_full_parsing_dictionary camera_obj extraItems: =
(
local parsing_dictionary = #()
join parsing_dictionary (compose_parsing_dictionary camera_obj)
--append extra items first. they should not be the same as the ones computed in this function
if extraItems != unsupplied then
(
if (classof extraItems) == Array then
(
for item in extraItems do
append parsing_dictionary item
)
)
mainoutput = batchCameraRender_getUserProperty camera_obj "BatchCameraRender_render_output"
if isNotUndefined mainoutput then
mainoutput = parse_file_name_template mainoutput parsing_dictionary --parse it by using usual dictionary
else
mainoutput = "mainoutput"
--exclude filename only
mainFileNameOnly = getFilenameFile mainOutput
--exclude path onle
mainPath = getFilenamePath mainOutput
append parsing_dictionary #("mainoutput", mainFileNameOnly)
append parsing_dictionary #("renderfile", mainFileNameOnly)
append parsing_dictionary #("mainpath", mainPath)
append parsing_dictionary #("renderpath", mainPath)
parsing_dictionary
)
fn getDefaultFrameRangeValue camera_object property_name =
(
result_value = undefined
localINI_path = maxFilePath
if localINI_path != "" then
(
found_value = false
while (not found_value) and (localINI_path != "") do
(
localINI_file = pathConfig.appendPath localINI_path "BatchCameraRender.ini"
if (doesFileExist localINI_file) then
(
--get the framerange value from the local ini file.
framerange_data1 = loadVarFromIniFile "Default Settings" "BatchCameraRender_frames" local_path:localINI_path
framerange_data2 = loadVarFromIniFile "Default Settings" "BatchCameraRender_framerange_from" local_path:localINI_path
framerange_data3 = loadVarFromIniFile "Default Settings" "BatchCameraRender_framerange_to" local_path:localINI_path
framerange_data4 = loadVarFromIniFile "Default Settings" "BatchCameraRender_anim_frame_range" local_path:localINI_path
found_value = case of
(
(isNotUndefined framerange_data1): true
(isNotUndefined framerange_data2): true
(isNotUndefined framerange_data3): true
(isNotUndefined framerange_data4): true
default: false
)
if (found_value) then
result_value = loadVarFromIniFile "Default Settings" property_name local_path:localINI_path
)
if (not found_value) then
localINI_path = pathConfig.removePathLeaf localINI_path --move to upper folder if ini file not found OR value in found ini file not found
)
if (not found_value) then
result_value = loadVarFromIniFile "Default Settings" property_name
)
else --if local path is invalid
result_value = loadVarFromIniFile "Default Settings" property_name
result_value
)
--get default value for the property from the global or local ini files
fn getDefaultValue camera_object property_name =
(
result_value = undefined
global_found_ini_file_paths = #()
--try to find local ini file recursively starting from scene folder and down to root folder.
--check each file if it contains default value
--if none of them contains default value, fall to the global ini file
localINI_path = maxFilePath
if localINI_path != "" then
(
found_value = false
while (not found_value) and (localINI_path != "") do
(
localINI_file = pathConfig.appendPath localINI_path "BatchCameraRender.ini"
if (doesFileExist localINI_file) then
(
appendIfUnique global_found_ini_file_paths localINI_file
result_value = loadVarFromIniFile "Default Settings" property_name local_path:localINI_path
if (isNotUndefined result_value) then
found_value = true
)
if (not found_value) then
localINI_path = pathConfig.removePathLeaf localINI_path --move to upper folder if ini file not found OR value in found ini file not found
)
if (not found_value) then
result_value = loadVarFromIniFile "Default Settings" property_name
)
else
result_value = loadVarFromIniFile "Default Settings" property_name
Net_Render_Options_Rollout.found_local_ini_files.items = global_found_ini_file_paths
result_value
)
--getUserProp wrapper to change property saving mechanism in future
--to change it from user properties to appdata
--also added default value mechanism
fn getUserProperty camera_object property_name=
(
if (camera_object != undefined) then
(
property_value = getAppData camera_object (propName2Id property_name)
if (isUndefined property_value) then --try to read default setting from the INI file.
(
--if the property is frame range property check all other frame range properties and only if all that properties are undefined return default property.
if (isFrameRangeProperty property_name) then
(
if (isFrameRangeUndefined camera_object) then --if frame range is undefined in object's data get it from the default
property_value = getDefaultFrameRangeValue camera_object property_name
)
else
property_value = getDefaultValue camera_object property_name
)
(if (isNotUndefined property_value) then property_value else undefined)
)
)
batchCameraRender_getUserProperty = getUserProperty
-- batchCameraRender_getRootNodeData = getRootNodeData
fn saveDefaultValues camera_object property_names =
(
try
ini_file_name = getSaveFileName caption:"INI File Name" filename:"BatchCameraRender.ini" types:"INI files (*.ini)|*.ini|All files (*.*)|*.*|" historyCategory:"Scripts"
catch (getCurrentException())
if ini_file_name != undefined then
(
ini_file_path = getFilenamePath ini_file_name
for property_name in property_names do
(
property_value = getUserProperty camera_object property_name
saveVar2IniFile "Default Settings" property_name (property_value as string) local_path:ini_file_path
)
)
)
--returns true if current renderer is Vray
fn isVrayRenderer =
(
(findString ((classof (renderers.current)) as string) "v_ray") != undefined
)
fn isPathAbsolute path_string =
(
pathConfig.isUncPath path_string or pathConfig.isPathRootedAtDriveLetter path_string
)
--function to switch render buttons' activity state
fn render_buttons_active state =
(
--main section
batchCameraRender_mainRollOut.render_start.enabled = state
batchCameraRender_mainRollOut.net_render.enabled = state
batchCameraRender_mainRollOut.show_net_submit.enabled = \
batchCameraRender_mainRollOut.net_render.checked and batchCameraRender_mainRollOut.net_render.enabled
)
--function to switch window element's activity state
fn elements_active state =
(
-- stack showLocals:false firstFrameOnly:false excludeOwner:true
batchCameraRender_mainRollOut.select_camera.enabled = state
batchCameraRender_mainRollOut.set_viewport.enabled = state
batchCameraRender_mainRollOut.check_selected.enabled = state
if (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Count == 1) then
(
Net_Render_Options_Rollout.save_all_as_default.enabled = true
batchCameraRender_mainRollOut.copy_button.enabled = true
batchCameraRender_mainRollOut.add_button.enabled = ((superclassof (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Item[0].tag.value) == camera))
)
else
(
Net_Render_Options_Rollout.save_all_as_default.enabled = false
batchCameraRender_mainRollOut.copy_button.enabled = false
batchCameraRender_mainRollOut.add_button.enabled = false
)
if (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Count > 0) then
(
batchCameraRender_mainRollOut.paste_button.enabled = (BatchCamRenderParamsBuffer != undefined)
batchCameraRender_mainRollOut.remove_button.enabled = true
)
else
(
batchCameraRender_mainRollOut.paste_button.enabled = false
batchCameraRender_mainRollOut.remove_button.enabled = false
)
--output section
for control_element in Render_Output_Rollout.controls do
control_element.enabled = state
--vray settings section
if isVrayRenderer() then
(
for control_element in Vray_Settings_Rollout.controls do
(
control_element.enabled = state
)
Vray_Settings_Rollout.save_vray_image_file.enabled = Vray_Settings_Rollout.save_separate_render_channels.enabled = Vray_Settings_Rollout.show_vray_vfb.checked and state
)
else
for control_element in Vray_Settings_Rollout.controls do
control_element.enabled = false
--lights section
for control_element in Light_Assignement_Rollout.controls do
control_element.enabled = state
--frame range section
for control_element in Frame_Range_Rollout.controls do
control_element.enabled = state
--resolution section
for control_element in Output_Size_Rollout.controls do
control_element.enabled = state
if Output_Size_Rollout.lock_aspect.checked then
Output_Size_Rollout.image_aspect_spinner.enabled = false
--scene state section
for control_element in Scene_States_Rollout.controls do
(
case (control_element.name) of
(
"state_sets_list": control_element.enabled = state and (dotnetclass "Autodesk.Max.StateSets.Plugin" != undefined)
default: control_element.enabled = state
)
)
)
--function to set all elements "enabled" state depending on list item's selection
fn ui_elements_refresh listview_obj =
(
--if there's no elements in list then deactivate all elements
if listview_obj.Items.count == 0 then
(
--no camera in scene
--deactivate render buttons
render_buttons_active false
elements_active false
--and all other elements too
for control_element in batchCameraRender_mainRollOut.controls do
(
case (control_element.name) of
(
"Refresh": control_element.enabled = true
-- "ADD_BUTTON": control_element.enabled = true
default: control_element.enabled = false
)
)
)
else --if there is something...
(
--make listview active
for control_element in batchCameraRender_mainRollOut.controls do
(
if control_element.name == "paste_button" then
control_element.enabled = (BatchCamRenderParamsBuffer != undefined)
else
control_element.enabled = true
)
--if something is checked then activate render buttons
render_buttons_active (listview_obj.CheckedItems.Count > 0)
--if something selected activate all elements and fill some fields
elements_active (listview_obj.SelectedItems.count > 0)
if listview_obj.SelectedItems.count > 1 then
(
batchCameraRender_mainRollOut.set_viewport.enabled = false
)
)
)
fn leadingZero num digitCount=
(
str = num as string
while str.count < digitCount do
str = "0" + str
str
)
fn submit_to_deadline camera_obj =
(
global SMTDPaths
global SMTDSettings
global SMTDFunctions
local theNetworkRoot = Net_Render_Options_Rollout.DeadlineRepo.text
local remoteScript = theNetworkRoot + @"\submission\3dsmax\main\SubmitMaxToDeadline_Functions.ms"
fileIn remoteScript
SMTDFunctions.loadSettings()
local jobName = ""
jobNamePattern = Net_Render_Options_Rollout.backburnerJobNamePattern.text
if (isNotUndefinedOrEmpty jobNamePattern) then
jobName = parse_file_name_template jobNamePattern (compose_full_parsing_dictionary camera_obj)
else
jobName = (if maxFileName == "" then "untitled" else maxFileName) + " " + camera_obj.name
SMTDSettings.JobName = jobName
local maxFileToSubmit = SMTDPaths.tempdir + (if maxFileName == "" then "untitled.max" else maxFileName)
SMTDFunctions.SaveMaxFileCopy maxFileToSubmit
local SubmitInfoFile = SMTDPaths.tempdir + "\\batchcam_submit_info.job"
local JobInfoFile = SMTDPaths.tempdir+ "\\batchcam_job_info.job"
--rendOutputFilename = SMTDFunctions.GetFormattedOutputFilename rendOutputFilename addFramePadding:true stripPaddingNumbers:true addFrameDelimiter:true
SMTDSettings.SubmitSceneMode = #reposave
--SMTDSettings.SubmitSceneMode = #networksave
--SMTDSettings.SubmitSceneNetworkLocation = maxFileToSubmit
SMTDFunctions.CreateSubmitInfoFile SubmitInfoFile batchName:(getFilenameFile (if maxFileName == "" then "Untitled.max" else maxFileName))
SMTDFunctions.CreateJobInfoFile JobInfoFile
local initialArgs="\""+SubmitInfoFile+"\" \""+JobInfoFile+"\" \""+maxFileToSubmit+"\" "
SMTDFunctions.waitForCommandToComplete initialArgs SMTDSettings.TimeoutSubmission
)
--function to submit current scene to backburner manager
fn net_render_auto_submit camera_obj =
(
batchManager = NetRender.GetManager() --get NetRender Interface