forked from jchristel/SampleCodeRevitBatchProcessor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModifyRevitFileSaveAs.py
108 lines (89 loc) · 2.98 KB
/
ModifyRevitFileSaveAs.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#License:
#
#
# Revit Batch Processor Sample Code
#
# Copyright (c) 2020 Jan Christel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# sample description
# this sample shows how to detach and save a file somwhere else and or under a different name
# list of end this file provides a mapping from the old file name to the new file name
import clr
import System
# flag whether this runs in debug or not
debug_ = False
# --------------------------
#default file path locations
# --------------------------
# store output here:
rootPath_ = r'C:\temp'
# path to Common.py
commonlibraryDebugLocation_ = r'C:\temp'
# debug mode revit project file name
debugRevitFileName_ = r'C:\temp\Test_Files.rvt'
# Add batch processor scripting references
if not debug_:
import revit_script_util
import revit_file_util
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
# NOTE: these only make sense for batch Revit file processing mode.
doc = revit_script_util.GetScriptDocument()
revitFilePath_ = revit_script_util.GetRevitFilePath()
else:
# get default revit file name
revitFilePath_ = debugRevitFileName_
# set path to common library
import sys
sys.path.append(commonlibraryDebugLocation_)
#import common library
import Common as com
from Common import *
# import Result as res #not required in this module
clr.AddReference('System.Core')
clr.ImportExtensions(System.Linq)
from Autodesk.Revit.DB import *
# output messages either to batch processor (debug = False) or console (debug = True)
def Output(message = ''):
if not debug_:
revit_script_util.Output(str(message))
else:
print (message)
# -------------
# my code here:
# -------------
# main:
# -------------
# list containing the default file names:
# [[revit host file name before save, revit host file name after save]]
defaultFileNames_ = [
['Test_Files', 'Test_Files_new']
]
# save revit file to new location
Output('Modifying Revit File.... start')
result_ = com.SaveAs(doc, revitFilePath_, defaultFileNames_)
# make further changes as required....
Output('Modifying Revit File.... status: ' + str(result_.status))
# sync changes back to central
if (doc.IsWorkshared and debug_ == False):
Output('Syncing to Central: start')
syncing_ = com.SyncFile (doc)
Output('Syncing to Central: finished ' + str(syncing_.status))
Output('Modifying Revit File.... finished ')