[Dynamo Pythonscript] Create Wall - using Revit api

I’m trying to create a wall using Pythonscript and revit api, but I don’t know how. Please help me.

1 Like

You have an error in the level input line
It should be
level = UnwrapElement(IN[0])

0 not 1 judging from your node setup

actually your node inputs don’t match ones in code - you should start with fixing that…

You can try a script like this:

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

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import Wall

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
level = UnwrapElement(IN[0])
lines = UnwrapElement(IN[1])

doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

walls = []

for l in lines:
	w = Wall.Create(doc, l.ToRevitType(), level.Id, False)
	walls.append(w)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = walls

Sorry, I uploaded the wrong image. Image modified.
One more time please.

python function len(something) gives you an integer length of ‘something’. You cannot iterate over integer - that is your error in yellow. To do an indexed iteration like so check the ‘range’ function in python…However there is no need to use indices - check my answer above (the one with code).

Thank you, it was very helpful :>

I have one more question.
Can I create walls without using curves and wall types?

Thank you for your kind answer.

I believe there is no function in RevitAPI that creates wall without specifying a location curve.

As for the type - it is not a wall type. This conversion is necessary because Dynamo objects are not Revit objects. So in order to pass a curve as a parameter to Revit API function it has to be converted from Dynamo-kind curve into Revit-kind curve.

3 Likes

It will not run.

AttrubuteError : ‘type’ object has no attrubute ‘Create’

@yongsuk

In your Script there is a conflict ‘Wall’s Class’ between 2 Namespaces
Revit.Elements and Autodesk.Revit.DB

from Autodesk.Revit.DB import Wall
from Revit.Elements import *

one solution is to assign the Revit class Wall to an alias (example RvtWall)

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

#import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import Wall as RvtWall

clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument

level = UnwrapElement(IN[0])
lines = UnwrapElement(IN[1])
walls = []
TransactionManager.Instance.EnsureInTransaction(doc)
for l in lines:
	w = RvtWall.Create(doc, l.ToRevitType(), level.Id, False)
	walls.append(w)
TransactionManager.Instance.TransactionTaskDone()
OUT = walls
3 Likes

It is way easier just to remove the line that brings confusion and is unneccessary

In general it is best practice not to use ‘*’ on imports and import only stuff you need.

3 Likes

Hi @c.poupin

How do you control the height of the created wall?

Thanks

@antoniocanerosan
you can use this method instead

1 Like

Thanks @c.poupin

I have issues getting the wallType.Id, could you please assist?

Note: lines list IN[0] are a list of polygons

#The inputs to this node will be stored as a list in the IN variables.
output = []
lines = IN[0].ToRevitType()

doc = DocumentManager.Instance.CurrentDBDocument

#Create Curve Array
carray = CurveArray()
		
#Loop through lines
for line in lines:
	carray.Append(line)
		
#Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

#Create Floor
floor = doc.Create.NewFloor(carray, False)
output.append(floor.ToDSType(False))

#Get Floor Parameters
level = floor.LookupParameter("Level").AsElementId()
height = 1000
offset = 5
#wallType = 2763524

#Create Walls
for line in lines:
	wall = Wall.Create(doc, line, wallType.Id, level,height,offset,False, False)
	output.append(wall.ToDSType(False))

#End Transaction
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = output, level

Thanks in advance

@antoniocanerosan
you can use the OOTB node “Wall Types”

1 Like

Merci beaucoup @c.poupin !
Appreciate your answer always!