Select elements on level and change to another level

One of our users inadvertently placed a bunch of building elements on a temporary level she no longer needs. The temporary level is at the same elevation as the target level. I have used the following graph:

The Python script is:

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument

element = UnwrapElement(IN[0])
ref_level = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

for i,x in enumerate(element):
	ref_levelid = ref_level[i].Id
	
	object_param_level = x.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM)

	object_level = doc.GetElement(object_param_level.AsElementId())

	object_param_level.Set(ref_levelid)

TransactionManager.Instance.TransactionTaskDone()

OUT = element

The python script is failing at the line that reads, “ref_level = UnwrapElement(IN[1])”. The error message reaferenses: “IndexError: Indev out of range: 1”.

Does anyone out there know how to fix this (with a good explanation of why)?

1 Like

@jorgedelacova7458

Hi,

You need to add another input (plus sign “+”) to the Python node.

Regards,

New to Python. Where should I add the plus sign? And thanks for the quick response!

@jorgedelacova7458

PythonScript

Be sure you are connecting the right data in each input.

1 Like

Oh, OK. Thanks.

image002.png

1 Like

I have added another input and connected the target level and list of elements to the Python Script node. Now I het an error on line 34. “TypeError: 'Level” is not subscriptable." Doing an Internet search on that now.

i tried also your script!

it finds just system families :frowning:
and some stuff can`t read:

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument

element = UnwrapElement(IN[0])
ref_level = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

for i,x in enumerate(element):
	ref_levelid = ref_level[i].Id

	object_param_level = x.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM)

	object_level = doc.GetElement(object_param_level.AsElementId())

	object_param_level.Set(ref_levelid)

TransactionManager.Instance.TransactionTaskDone()

OUT = element

i think it is better start a new topic