Error:"Value cannot be null". Create spaces automatically

Hello, I know this topic was discussed. I need to creat a spaces which based on rooms from linked file. I picked the code from this topic: http://dynamobim.org/forums/topic/create-spaces-automatically/ .
Actually, I have 2 opthions of error:

  1. “Value cannot be null”- if I get levels by this way : lvls1 = FilteredElementCollector(doc).OfClass(Level).WhereElementIsNotElementType().ToElements()
    Here lvls1[2] is level of second floor.
  2. " ‘Level’ object is unsubscriptable" - if I get level by nodes.
    I don’t understand, this elements is the same it has the same ID. But two different error. Why? Can you help me? What is the reason of this error: levels or rooms from linked file? I have tried to use levels from linked file too - the same error.
    Of course I have checked, input lists has not any null elements.