forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchConvertAutoCAD.rvb
78 lines (63 loc) · 2.53 KB
/
BatchConvertAutoCAD.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchConvertAutoCAD.rvb -- October 2008
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 4.0.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BatchConvertAutoCAD
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BatchConvertAutoCAD()
' Make sure RhinoScript does not reinitialize when opening models,
' otherwise this script will only process one file.
Rhino.Command "_-Options _RhinoScript _Reinitialize=_No _Enter _Enter", 0
' Allow the user to interactively pick a folder
Dim sFolder
sFolder = Rhino.BrowseForFolder(, "Select folder to process", "Batch Convert AutoCAD")
If VarType(sFolder) <> vbString Then Exit Sub
' Create a file system object
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Get a folder object based on the selected folder
Dim oFolder
Set oFolder = oFSO.GetFolder(sFolder)
' Process the folder
ProcessFolder oFSO, oFolder
' Release the objects
Set oFolder = Nothing
Set oFSO = Nothing
' Close the last file processed
Rhino.DocumentModified False
Rhino.Command "_-New _None", 0
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ProcessFolder
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ProcessFolder(oFSO, oFolder)
' Process all .dwg files in the selected folder
Dim oFile, strOpen, strSave
For Each oFile In oFolder.Files
If LCase(oFSO.GetExtensionName(oFile.Path)) = "dwg" Then
strOpen = LCase(oFile.Path)
strSave = LCase(Replace(strOpen, ".dwg", ".3dm", 1, -1, 1))
ProcessFile strOpen, strSave
End If
Next
' Comment out the following lines if you do not
' want to recursively process the selected folder.
Dim oSubFolder
For Each oSubFolder In oFolder.SubFolders
ProcessFolder oFSO, oSubFolder
Next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ProcessFile
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ProcessFile(strOpen, strSave)
Rhino.DocumentModified False
Rhino.Command "_-Open " & Chr(34) & strOpen & Chr(34), 0
Rhino.Command "_-Zoom _All _Extents", 0
Rhino.Command "_-SetActiveView _Top", 0
Rhino.Command "_-Save " & Chr(34) & strSave & Chr(34), 0
End Sub