forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchAudit3dm.rvb
93 lines (75 loc) · 2.96 KB
/
BatchAudit3dm.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchAudit3dm.rvb -- January 2014
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 5.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchAudit3dm
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BatchAudit3dm
' Declare local variables
Dim sFolder, oFSO, oFolder
Dim strTitle, nRecurse, blnCheck
strTitle = "Batch Audit 3DM"
' Make sure were are running Rhino 5.
If (Rhino.ExeVersion < 5) Then
Call Rhino.Print("This script requires Rhino 5.0 for greater.")
Exit Sub
End If
' Browse to a folder you want to process
sFolder = Rhino.WorkingFolder
sFolder = Rhino.BrowseForFolder(sFolder, "Select folder to process", strTitle)
If IsNull(sFolder) Then Exit Sub
' Should we recurse through subfolders?
nRecurse = Rhino.MessageBox("You want to process each subfolder in this folder?", 35, strTitle)
If nRecurse = vbCancel Then Exit Sub
' Create file system and folder objects
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sFolder)
' Turn off bad object error checking
blnCheck = Rhino.CheckNewObjects(False)
' Call our worker procedure
Call DoAudit(oFSO, oFolder, nRecurse)
' Clean up and finish
Call Rhino.CheckNewObjects(blnCheck)
Call Rhino.DocumentModified(False)
Call Rhino.Command("_-New _None", 0)
Call Rhino.Print("Done!")
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DoAudit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DoAudit(oFSO, oFolder, nRecurse)
' Declare local variables
Dim oFile, strOpen, strSave, oSubFolder
' Process each file in the folder
For Each oFile In oFolder.Files
' Process only 3dm files
If LCase(oFSO.GetExtensionName(oFile.Path)) = "3dm" Then
strOpen = LCase(oFile.Path)
strSave = LCase(Replace(strOpen, ".3dm", "_audit.txt", 1, -1, 1))
' Here we go...
Call Rhino.DocumentModified(False)
' Audit the file
Call Rhino.Command("_-Audit3dmFile " & DoubleQuote(strOpen) & " _File " & DoubleQuote(strSave))
End If
Next
If nRecurse = vbYes Then
For Each oSubFolder In oFolder.SubFolders
Call DoAudit(oFSO, oSubFolder, nRecurse)
Next
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DoubleQuote
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function DoubleQuote(str)
DoubleQuote = Chr(34) & str & Chr(34)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Drag & drop support
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Call Rhino.AddStartupScript(Rhino.LastLoadedScriptFile)
Call Rhino.AddAlias("BatchAudit3dm", "_NoEcho _-RunScript (BatchAudit3dm)")