Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Transfer walltypes to project python

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ckepner
734 Views, 2 Replies

Transfer walltypes to project python

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)
Labels (3)
2 REPLIES 2
Message 2 of 3
jeremytammik
in reply to: ckepner

What issue?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3
Revitalizer
in reply to: ckepner

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




Rudolf Honke
Software Developer
Mensch und Maschine





Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community