Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·126 lines (116 loc) · 3.71 KB
/
Copy pathmain.py
File metadata and controls
executable file
·126 lines (116 loc) · 3.71 KB
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
"""
=========================================================
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Title: Rhino Layer State Batch Render
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
=========================================================
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Author: Vlad
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Description:
The Script renders all the named views with
and goes through all the layer states
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Notes:
The folder destination, layerstate name,
& view names must be clear of characters
which cannot be part of a file's name (i.e.
Tilde (~)
Number sign (#)
Percent (%)
Ampersand (&)
Asterisk (*)
Braces ({ })
Backslash (\)
Colon (:)
Angle brackets (< >)
Question mark (?)
Slash (/)
Plus sign (+)
Pipe (|)
Quotation mark (")
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
=========================================================
"""
import rhinoscriptsyntax as rs
import sys
def ChangeLayerState(LayerState):
"""
Receives a LayerState and changes
the model to that specific LayerState
"""
plugin = rs.GetPlugInObject("Rhino Bonus Tools")
if plugin is not None:
plugin.RestoreLayerState(LayerState, 0)
return 1
else :
return 0
def GetLayerStates():
"""
The function returns the LayerStates
that can be found in the model
"""
plugin = rs.GetPlugInObject("Rhino Bonus Tools")
if plugin is not None:
MyArray = plugin.LayerStateNames
MyArrayB = []
MyArray = str(MyArray[1])
Trigger = True
while (Trigger):
poz=MyArray.rfind("'")
MyArray = MyArray[:poz]
poz=MyArray.rfind("'")
dif = MyArray[poz:]
dif = dif[1:]
MyArrayB.append(dif)
MyArray = MyArray[:poz]
if len(MyArray)<14:
Trigger = False
del MyArrayB[-1] #clean up the list
return MyArrayB
def GetViewNames():
"""
Returns a string of defining
the NamedViews that can be found
in the file
"""
a = rs.NamedViews()
return a
def ChooseFolderPath():
"""
pick a folder to save the renderings to
return the folder
"""
folder = rs.BrowseForFolder(rs.DocumentPath, "Browse for folder", "Batch Render")
return folder
def Render(folder,View,State):
"""
Defines the Rendering action
Saves the render to the browsed folder
Adds the name of the view and the name
of the layer state to the naming of the
view
"""
FileName = '"'+folder +'\\'+View+'_'+State+'"'
FileName = str(FileName)
rs.Command ("!_-Render")
rs.Command ("_-SaveRenderWindowAs "+FileName)
rs.Command ("_-CloseRenderWindow")
return 1
def ChangeView(View):
rs.Command ("_-NamedView _Restore " + View + " _Enter", 0)
if __name__ == "__main__":
"""
Main Function
"""
VRay = rs.GetPlugInObject("V-Ray for Rhino")
VRay.SetBatchRenderOn(True) #Set Batch Render on True
arrStates = GetLayerStates() #initialise layer states
arrViewNames = GetViewNames()
folder = ChooseFolderPath()
for State in arrStates:
ChangeLayerState(State)
print (State)
for View in arrViewNames:
ChangeView(View)
Render(folder,View,State)