Can not create walls by lines

Hi all,

I’m using Revit python shell and I’m traying to create walls from lines using profil method as described below:

But I’m getting the following error in the RPS console, which I suppose would be the same in Dynamo.

Exception : Autodesk.Revit.Exceptions.InvalidOperationException: Could not construct a proper face with the input curves to create a wall correctly.
à Autodesk.Revit.DB.Wall.Create(Document document, IList`1 profile, ElementId wallTypeId, ElementId levelId, Boolean structural)

Here my code:

from Autodesk.Revit.DB import *
from System.Collections.Generic import IList, List
uidoc = __revit__.ActiveUIDocument

doc = uidoc.Document


t = Transaction(doc, 'create Model lines')

wall_Types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.INVALID).OfClass(WallType).ToElementIds()
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.INVALID).OfClass(Level).ToElementIds()

for w in wall_Types:
    w_type = doc.GetElement(w)
    if w_type.Name == "Ext. Voile BA 20":
        wall_Id = w
    
for l in levels:
    lvl = doc.GetElement(l)
    if lvl.Name == "Niveau 0":
        lvl_Id = l

# Create Points and Lines:

c = 1/0.3048
Pt0 = XYZ(-0.60*c,-0.60*c,0)
Pt1 = XYZ(0.60*c,-0.60*c,0)
Pt2 = XYZ(0.60*c,0.60*c,0)
Pt3 = XYZ(-0.60*c,0.60*c,0)

Lines = []
Line1 = Line.CreateBound(Pt0, Pt1)
Lines.append(Line1)
Line2 = Line.CreateBound(Pt1, Pt2)
Lines.append(Line2)
Line3 = Line.CreateBound(Pt2, Pt3)
Lines.append(Line3)
Line4 = Line.CreateBound(Pt3, Pt0)
Lines.append(Line4)

Curves = List[Curve]()

for i in Lines:
    Curves.Add(i)

t.Start()

Walls = Wall.Create(doc, Curves, wall_Id, lvl_Id, True)

t.Commit()

Any help would be appreciated

Thanks.

Hi @REDO10

Z values cannot be identical

import clr
import sys
import System
#
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

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


#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary

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

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)

TransactionManager.Instance.ForceCloseTransaction()
t = Transaction(doc, 'create Model lines')

wall_Type = FilteredElementCollector(doc).OfClass(WallType).WhereElementIsElementType().First(lambda x : x.ToDSType(False).Name == "Générique - 200 mm")
level = FilteredElementCollector(doc).OfClass(Level).First(lambda x : x.ToDSType(False).Name == "Niveau 1")

# Create Points and Lines:

c = 1/0.3048
Pt0 = XYZ(-0.60*c, 0, -0.60*c)
Pt1 = XYZ(0.60*c, 0, -0.60*c)
Pt2 = XYZ(0.60*c, 0, 0.60*c)
Pt3 = XYZ(-0.60*c, 0, 0.60*c)

Lines = []
Line1 = Line.CreateBound(Pt0, Pt1)
Lines.append(Line1)
Line2 = Line.CreateBound(Pt1, Pt2)
Lines.append(Line2)
Line3 = Line.CreateBound(Pt2, Pt3)
Lines.append(Line3)
Line4 = Line.CreateBound(Pt3, Pt0)
Lines.append(Line4)

Curves = List[Curve]()

for i in Lines:
    Curves.Add(i)

t.Start()

wall = Wall.Create(doc, Curves, wall_Type.Id, level.Id, True)

t.Commit()

OUT = wall
2 Likes

Hi @c.poupin

Effectively, I discovered my mistake and corrected it. I initially chose the wrong method, which created a wall profile based on lines in the XZ or YZ plane, but I wanted to create walls based on lines in the XY plane. To solve this, I should have used the method you employed, which resolves my issue.

Thanks a lot Cyril :wink:

2 Likes