forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchSaveSmall.rvb
130 lines (100 loc) · 3.45 KB
/
BatchSaveSmall.rvb
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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchSaveSmall.rvb -- October 2013
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhinoceros 5.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Main subroutine
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BatchSaveSmall()
Dim sFolder, oFSO, oFolder
' Hey, only Rhinoceros 5...
If (Rhino.ExeVersion < 5) Then
Call Rhino.Print("This script requires Rhinoceros 5 or greater.")
Exit Sub
End If
' Pick a folder
sFolder = Rhino.BrowseForFolder(, "Select folder to recurse", "Batch SaveSmall")
If IsNull(sFolder) Then Exit Sub
' Get the folder from the file system
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sFolder)
' Do the recursive small saving...
Call RecurseSaveSmall(oFolder)
' Clean up
Call Rhino.DocumentModified(False)
Call Rhino.Command("_-New _None", 0)
Call Rhino.Print("Done!")
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' RecurseSaveSmall
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub RecurseSaveSmall(oFolder)
Dim oFile, oSubFolder, dModified
For Each oFile In oFolder.Files
' Save file modified date
dModified = oFile.DateLastModified
' Do the "save small"
Call DoSaveSmall(oFile.Path, dModified)
Next
' If you do not want to recurse folders,
' just comment the following lines.
For Each oSubFolder In oFolder.SubFolders
Call RecurseSaveSmall(oSubFolder)
Next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DoSaveSmall
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DoSaveSmall(sPath, dModified)
Dim aViews, sView, aInfo, sVer, sCmd
If InStr(LCase(sPath), ".3dm") > 0 Then
' Find the file version
sVer = "5"
aInfo = Rhino.DocumentInfo(sPath)
If IsArray(aInfo) Then
Select Case aInfo(1)
Case 3 sVer = "3"
Case 30 sVer = "3"
Case 4 sVer = "4"
Case 40 sVer = "4"
Case 5 sVer = "5"
Case 50 sVer = "5"
End Select
End If
Rhino.Print aInfo(1)
Rhino.Print sVer
' Open the file
Call Rhino.DocumentModified(False)
Call Rhino.Command("_-Open " & Chr(34) & sPath & Chr(34), 0)
' Set all of the viewports to wireframe before saving
aViews = Rhino.ViewNames
For Each sView In aViews
Call Rhino.ViewDisplayMode(sView, 0)
Next
' Save it
sCmd = "_-SaveSmall _Version=" & sVer
sCmd = sCmd & " _SaveSmall=_Yes _GeometryOnly=_No _SaveTextures=_No _SavePlugInData=_No _Enter"
Call Rhino.Command(sCmd, 1)
' Clear the undo stack
Call Rhino.Command("_-ClearUndo", 0)
' Reset file modified date
Call TouchDateModified(sPath, dModified)
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' TouchDateModified
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub TouchDateModified(sPath, dModified)
Dim oShell, oFolder, oFile
Dim sDir, sFile, nPos
nPos = InStrRev(sPath, "\")
sDir = Left(sPath, nPos)
sFile = Mid(sPath, nPos + 1)
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.NameSpace(sDir)
Set oFile = oFolder.ParseName(sFile)
oFile.ModifyDate = dModified
End Sub