forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchRemovePlugInData.rvb
107 lines (89 loc) · 3.39 KB
/
BatchRemovePlugInData.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchRemovePlugInData.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
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchRemovePlugInData
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BatchRemovePlugInData
' Declare local variables
Dim sFolder, oFSO, oFolder
Dim strTitle, nRecurse, blnCheck
strTitle = "Batch Remove Plug-in Data"
' 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 DoRemovePlugInData(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
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DoRemovePlugInData
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DoRemovePlugInData(oFSO, oFolder, nRecurse)
' Declare local variables
Dim oFile, strOpen, arrInfo, strVer, 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)
' Determine the 3dm file version
arrInfo = Rhino.DocumentInfo(strOpen)
If IsArray(arrInfo) Then
If arrInfo(1) = 2 Then
strVer = "_Version=2"
ElseIf arrInfo(1) = 3 Then
strVer = "_Version=3"
ElseIf arrInfo(1) = 4 Then
strVer = "_Version=4"
Else
strVer = "_Version=5"
End If
' Here we go...
Call Rhino.DocumentModified(False)
' Open the file
Call Rhino.Command("_-Open " & DoubleQuote(strOpen))
' Save it without plug-in data
Call Rhino.Command("_-Save " & strVer & " _SavePlugInData=_No _Enter", 0)
End If
End If
Next
If nRecurse = vbYes Then
For Each oSubFolder In oFolder.SubFolders
Call DoRemovePlugInData(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("BatchRemovePlugInData", "_NoEcho _-RunScript (BatchRemovePlugInData)")