-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCloneViewTypes.py
More file actions
119 lines (101 loc) · 3.64 KB
/
CloneViewTypes.py
File metadata and controls
119 lines (101 loc) · 3.64 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#---------------------------------------------------------------#
#
# Pre-requisites:
# ---------------
#
# 1.
# You need to have already transferred your view templates
# using Transfer Project Standards so that this script can
# match up the default templates when re-creating the view
# types in this file.
#
#---------------------------------------------------------------#
sourcedocName = 'Project1'
#---------------------------------------------------------------#
def getSourceProject(sourcedocName):
app = doc.Application
#Loop through all open documents searching for a match
for adoc in app.Documents:
#If we find a match return the document
if adoc.Title.Equals(sourcedocName):
return adoc
return false
#---------------------------------------------------------------#
def findMatchingLocalViewType(remoteType):
viewtypes = (
FilteredElementCollector(doc)
.OfClass(type(remoteType))
)
print 'viewtypes count = ' + viewtypes.Count().ToString()
x = viewtypes.FirstElement()
if x:
return x
else:
return None
#---------------------------------------------------------------#
def findMatchingTemplateByName(templateName):
localtemplates = (
FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Views)
#.Where(lambda v: v.IsTemplate)
)
print localtemplates.Count().ToString() + ' local View templates'
for aViewTemplate in localtemplates:
if aViewTemplate.Name.Equals(templateName):
return aViewTemplate
#If we get here we didn't find a match
return false
#---------------------------------------------------------------#
def cloneViewType(viewtype):
#Get the default template for the view type.
param = viewtype.LookupParameter('View Template applied to new views')
#Check the the parameter exists and has a value.
if param and param.HasValue:
vtId = param.AsElementId()
#Next make sure that it is a valid template ID
if vtId == ElementId.InvalidElementId:
print 'No Default Template'
else:
#Get the Template
template = sourcedoc.GetElement(vtId)
#Get the Template Name
templateName = Element.Name.GetValue(template)
#search for a template in the local document with the corresponding name
templatelocal = findMatchingTemplateByName(templateName)
viewtypelocal = findMatchingLocalViewType(viewtype)
print '... ' + viewtypelocal.FamilyName
#createNewViewType(typeName, defaultTemplate, CalloutType)
else:
print 'Param Not Found'
#---------------------------------------------------------------#
def getSourceViewTypes(sourcedoc):
theTypes = (FilteredElementCollector(sourcedoc)
.OfClass(ViewFamilyType)
.OrderBy(lambda t: t.FamilyName)
.ToList()
)
for aType in theTypes:
print aType.FamilyName + " -- " + Element.Name.GetValue(aType)
param = aType.LookupParameter('View Template applied to new views')
if param and param.HasValue:
vtId = param.AsElementId()
if vtId == ElementId.InvalidElementId:
print 'No Default Template'
else:
template = sourcedoc.GetElement(vtId)
print 'Template: ' + template.ToString()
templateName = Element.Name.GetValue(template)
print 'Template Name: ' + templateName
print '... cloning view type...'
cloneViewType(aType)
else:
print 'Param Value Not Found'
print '\n'
#---------------------------------------------------------------#
#Try and Get the Source Document
sourcedoc = getSourceProject(sourcedocName)
if sourcedoc:
#Get the Source Views
getSourceViewTypes(sourcedoc)
else:
print 'Source Document Not Found'