Get Type Id and level Id from Ids

Hi everyone

I’m getting this error in the RPS console when attempting to create walls

Exception : Microsoft.Scripting.ArgumentTypeException: expected BuiltInParameter, got ElementId
here my code:

from Autodesk.Revit.DB import *
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

selection = uidoc.Selection.GetElementIds()
wall_Types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.INVALID).OfClass(WallType).ToElements()
level_Types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.INVALID).OfClass(Level).ToElements()

for w in wall_Types:
    if w.Name == "Ext. Voile BA 20":
        wall_Id = w.Id

for l in level_Types:
    if l.Name == "Niveau 0":
        level_Id = l.Id

t = Transaction(doc, 'Create walls')

t.Start()

for s in selection:
    crv = doc.GetElement(s).GeometryCurve
    wall = Wall.Create(doc, crv, ElementId(wall_Id), ElementId(level_Id), 3.00, 0.00, False,True)
t.Commit()

What’s wrong in my code?

Thanks.

It’d would be helpful to note on which line you are getting error. But judging from this code it’s on FilteredElementCollector. As I’m writing from mobile I’ve no way to check to be sure but I’d remove method OfCategory(BuiltInCategory.INVALID) as it’s kind of contradicting with OfClass(WallType). Wall types are also part of BuiltInCategory.OST_Walls. Or change collector methods entirely to
OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType().ToElements().
As for BuiltInCategory.INVALID I wouldn’t be surprised if it were returning id: -1 so it would create this exception.

1 Like

@MarcinTalipski

As you can see below, I can collect all walls type and levels, so my collectors are defined correctly !!

My issue is due to the LevelId which I can’t define it correctly in the wall creation methode ?

When I entred these integer values for wall tye (29320) and levelId (608) it works !!?

wall = Wall.Create(doc, crv, ElementId(29320), ElementId(608), 3.00, 0.00, False,True)

how to solve this issue?

Thanks.

I see, I think I know what is going on. If you use [quote=“REDO_79, post:1, topic:3422”]
level_Id = l.Id
[/quote] you get element of ElementId class so you don’t need to retrieve it again. Try placing wall like this:
Wall = Wall.Create(doc, crv, (wall_Id), (level_Id), 3.00, 0.00, False,True)

1 Like

@MarcinTalipski

I tried your code. No error is given, but the walls aren’t being created.

Thanks.

You’ll have to debug it further, try printing this created wall, or even it’s Id number, if it exist, so you will be able to find in model.

hi @REDO_79 you have any update if you solved this? have you tried removing BuiltinCategory and just leave the OfClass in level_Types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.INVALID).OfClass(Level).ToElements()?

Hi @jmarkx

Yes, I initially used the wrong code, but I solved my issue by using this one:

levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).ToElements()

Thanks.