Huluru
Huluru

Reputation: 11

TypeError: 'NoneType' object is not iterable in maya python

I'm working on a python script for autodesk maya and I have a problem with the beginning of it since 3 weeks.

import maya.cmds as cmds
import os.path
import ntpath

  global directory_Seqs
  global directory_Seqs_2
  global direction_0
  global listSeqOption
  direction_0 = cmds.fileDialog2(fileMode=3,dialogStyle = 1)
  directory_Seqs = os.path.join(direction_0,'03_TRAVAIL','3D','SEQ')
  directory_Seqs_2 = os.path.normpath(directory_Seqs[0])

  print directory_Seqs_2

  listSeqOption = cmds.getFileList(directory_Seqs_2)
  for seq in listSeqOption :
      seq = cmds.menuItem('listSeq', label= seq , parent="UI_SeqOptionMenu")

it's working on linux, but i have a failure on windows :

   # TypeError: 'NoneType' object is not iterable # 

about

   listSeqOption

can someone know how to fix it ?

Upvotes: 1

Views: 2362

Answers (1)

theodox
theodox

Reputation: 12218

Maya is stupid about return values: if your file path is nonexistent the call to getFileList will return None instead of an empty list. It's a good habit to write it like this:

   listSeqOption = cmds.getFileList(directory_Seqs_2) or []

which will return an empty list even if the command returns None. The same is true with many other commands that should return lists, particularly ls.

Upvotes: 3

Related Questions