-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBatchProcessLinkUpdates.py
More file actions
94 lines (77 loc) · 3.07 KB
/
BatchProcessLinkUpdates.py
File metadata and controls
94 lines (77 loc) · 3.07 KB
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
import os
basepath = r'X:\BIM\5.0 Project Resources\Ian\TEST'
themodels = [
'TEST-01.rvt',
'TEST-02.rvt',
'TEST-03.rvt',
'TEST-04.rvt'
]
thepaths = []
app = uiapp.Application
class SynchLockCallback(ICentralLockedCallback):
def ShouldWaitForLockAvailability():
return False
#--------------------------------------------------------------------------------#
# Refer to https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-F99FBBCC-AE58-46F5-85AF-0A7C3C5C0576-htm.html?_ga=2.18634043.303903109.1543365649-1865787168.1469580492
#--------------------------------------------------------------------------------#
def GetLocalFilePath(filename):
#If we get a filename including the ".rvt" then remove it.
if filename.EndsWith('.rvt'):
fname = filename[:-4]
else:
fname = filename
#Rebuild the local file path
localpath = "C:\\REVIT_LOCAL" + app.VersionNumber + "\\" + fname + "_" + app.Username + "_Reload.rvt."
#Convert it to a modelpath and return it
modelpath = ModelPathUtils.ConvertUserVisiblePathToModelPath(localpath);
return modelpath
#--------------------------------------------------------------------------------#
def DoIt(apath):
#Handle to the Application
app = uiapp.Application
#Arguments required for the file open operation.
#centralfile = ModelPathUtils.ConvertUserVisiblePathToModelPath(apath)
opts = OpenOptions()
#opts.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach
#Create a New Local and open it.
centralfile = ModelPathUtils.ConvertUserVisiblePathToModelPath(apath)
#Grab Just the filename
fname = os.path.split(apath)[1]
#Create the local file modellpath
localfile = GetLocalFilePath(fname)
WorksharingUtils.CreateNewLocal(centralfile,localfile)
#--------------------+
# Open the Document. |
#--------------------+
currentdoc = uiapp.Application.OpenDocumentFile(localfile,opts)
#Setup the Transaction Options for the Synchronize
transOpts = TransactWithCentralOptions()
transCallback = SynchLockCallback()
transOpts.SetLockCallback(transCallback)
#Setup the Synchronization Options for the Synchronize
syncOpts = SynchronizeWithCentralOptions()
relinquishOpts = RelinquishOptions(True)
syncOpts.SetRelinquishOptions(relinquishOpts)
syncOpts.SaveLocalAfter = True
syncOpts.Comment = 'Automated Revit Links update'
#Synchronize the Document
try:
currentdoc.SynchronizeWithCentral(transOpts,syncOpts)
except Exception as e:
print 'Synchronization Failed:'
print e.message
#Then Close the Document
currentdoc.Close(True)
print 'Closed document: ' + apath
#Lastly remove the Local FIle
localpath = ModelPathUtils.ConvertModelPathToUserVisiblePath(localfile)
print 'Deleting Local File: ' + localpath
if os.path.exists(localpath):
os.remove(localpath)
#--------------------------------------------------------------------------------#
for amodel in themodels:
thepath = '\\'.join([basepath, amodel])
thepaths.Add(thepath)
for apath in thepaths:
print 'Opening document: ' + apath
DoIt(apath)