forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchSaveSTL.rvb
71 lines (50 loc) · 1.9 KB
/
BatchSaveSTL.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchSaveSTL.rvb -- January 2015
' 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 BatchSaveSTL
Dim sFolder, oFSO, oFolder
If (Rhino.ExeVersion < 5) Then
Call Rhino.Print("This script requires Rhinoceros 5 or greater.")
Exit Sub
End If
sFolder = Rhino.BrowseForFolder(, "Select folder to recurse", "Batch Save STL")
If IsNull(sFolder) Then Exit Sub
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sFolder)
Call RecurseFolder(oFolder)
Call Rhino.DocumentModified(False)
Call Rhino.Command("_-New _None", 0)
Call Rhino.Print("Done!")
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' RecurseFolder
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub RecurseFolder(oFolder)
Dim oFile, oSubFolder
For Each oFile In oFolder.Files
Call DoSaveAs(oFile.Path)
Next
For Each oSubFolder In oFolder.SubFolders
Call RecurseFolder(oSubFolder)
Next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DoSaveAs
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DoSaveAs(sPath)
Dim sCmd, sSave
If InStr(LCase(sPath), ".3dm") > 0 Then
sSave = LCase(Replace(sPath, ".3dm", ".stl", 1, -1, 1))
Call Rhino.DocumentModified(False)
Call Rhino.Command("_-Open " & Chr(34) & sPath & Chr(34), 0)
sCmd = "_-Save " & Chr(34) & sSave & Chr(34) & " _Enter _Enter"
Call Rhino.Command(sCmd, 1)
End If
End Sub