WallType.Duplicate with Python

Hello all!

So I am working on a Python script to batch create wall, floor, roof (etc) types in Revit. As I understand the simplest way (only way?) to create new types is to duplicate existing types and changing their parameters.

But I am stuck on the first step. I can seem to duplicate a wall type.
I get the error:

AttributeError: ‘WallType’ object has no attribute ‘Duplicate’

Python code:

import clr
# Import RevitAPI Classes
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import System

doc = DocumentManager.Instance.CurrentDBDocument

UIunit = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits
# Place your code below this line

basicwall = IN[0]
new_type = []
TransactionManager.Instance.EnsureInTransaction(doc)

new_type = basicwall.Duplicate("TEST")

TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = new_type

I figuered it out!

I have to Unwrap the elements first:

basicwall = UnwrapElement(IN[0])

Try getting the Revit element

basicwall = UnwrapElement(IN[0])

Also, you need to use the following
new_type.Add(basicwall.Duplicate())

2 Likes

Next problem… Now that I unwraped the type and duplicated it, I can not use the Set.ParameterByName method to change the parameters, right?

Do I have to wrap the type first? Or can I change the parameters while the wall type unwraped is?

You can do it with Python, or you probably need to use Transaction.End and Transaction.Start to make sure the new types are available for changing parameters.

No need for that! I just used the following API method so I dont need to wrap the wall types again:

element.LookupParameter(parameterName).Set(value)

hi! can you please show the full python code? thank you!

What exactly are you interested in? I can not copy the full code because this was only one part of a code that I needed to implement a bigger script.