I'm having trouble creating a python version of https://thebuildingcoder.typepad.com/blog/2015/05/transferring-a-wall-type.html
I want to collect all the walltypes of a project and transfer them into the new open model.
Issue is happening when I try to duplicate the walltype into the new model.
import clr
clr.AddReference("RevitNodes")
import Revit
clr.AddReference('RevitAPIUI')
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
clr.AddReference("RevitAPI")
import Autodesk
import System.Drawing
import System.Windows.Forms
from Autodesk.Revit.DB import *
from System.Drawing import *
from System.Windows.Forms import *
import System
from System.Collections.Generic import *
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
class SelectionForm(Form):
def __init__(self, SelNames):
self.revname = SelNames
self.Text = 'Transfer Elements'
self.label = System.Windows.Forms.Label()
self.label.Text = "Select Element Type"
self.label.Location = Point(1, 50)
self.label.Height = 30
self.label.Width = 200
self.count = 0
self.cb = System.Windows.Forms.ComboBox()
self.cb.Width = 200
self.cb.Height = 20
self.cb.Location = Point(15,20)
self.cb.DataSource = self.revname
self.button = System.Windows.Forms.Button()
self.button.Text = 'Element Type'
self.button.Location = Point(15,60)
self.button.Width = self.cb.Width
self.button.Height = 25
self.button.Click += self.button_click
self.Width = self.cb.Width + 50
self.Height = 150
self.Controls.Add(self.cb)
self.Controls.Add(self.button)
def button_click(self, sender, event):
self.selected = self.cb.SelectedValue
self.Close()
def filter_list(revisionlist, search_str):
passed = None
for element in revisionlist:
name = element.Name
if search_str == name:
passed = element
return passed
SelNames = ['Wall Types', 'Door Types', 'Casework Types']
form = SelectionForm(SelNames)
form.ShowDialog()
SelectedType = form.selected
options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets
if SelectedType == 'Wall Types':
FilePath = 'C:\Downloads\\project1.rvt'
modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(FilePath)
docFam = app.OpenDocumentFile(modelPath, options)
ElemCol = FilteredElementCollector(docFam).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType().ToElements()
elif SelectedType == 'Door Types':
FilePath = 'C:\Downloads\\project2.rvt'
modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(FilePath)
docFam = app.OpenDocumentFile(modelPath, options)
ElemCol = FilteredElementCollector(docFam).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsElementType().ToElements()
elif SelectedType == 'Casework Types':
FilePath = 'C:\Downloads\\project2.rvt'
modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(FilePath)
docFam = app.OpenDocumentFile(modelPath, options)
ElemCol = FilteredElementCollector(docFam).OfCategory(BuiltInCategory.OST_Casework).WhereElementIsElementType().ToElements()
else:
print('Select Element Type')
newwalltype = []
newwalls = []
for e in ElemCol:
tcheck = Transaction(doc, 'transfer element')
tcheck.Start()
try:
eleName = Element.Name.GetValue(e)
newwalls = e.Duplicate(eleName)
newwalltype.append(e)
except:
newwalltype.append(None)
tcheck.Commit()
print(newwalltype)
Solved! Go to Solution.
Solved by Revitalizer. Go to Solution.
What issue?
Hi,
duplicating an ElementType just operates on the same file.
You need ElementTransformUtils.CopyElements to transfer the types from one Revit file to another one.
Revitalizer
Can't find what you're looking for? Ask the community or share your knowledge.