Search code examples
python-2.7maya

Python Indentation Error on import statement?


I am writing a python script for the application maya. In the console i get this error:

# Error: IndentationError: file <maya console> line 2: expected an indented block # 

However this is a simple import statement. I'm not sure why i'm getting it, it ONLY happens on the statement "import neoARLLF". If it take it out, it doesn't give it anymore. The module is definitely in the folder with the rest of the scripts, otherwise i'd presume i'd get an import error. Further more all of the rest of the script is indented correctly, and i'm not mixing tabs and spaces, all of it is indented by 4 spaces.

import maya.cmds as mc
import neoARLLF
import neoARnameConv
reload(neoARnameConv)
reload(neoARLF)

seg = neoARLLF.MidLvlFunc()
nameC = neoARnameConv.NameConv()

def jntSegTest():
    jointRad = mc.joint("joint1", q=True, rad=True)
    jnts = 2
    names = []

    for i in xrange(1, 2, 1):
        name = nameC.curConv("test", "AuxKnee", "right", "joint", "01")
        names.append(name)

    seg.segmentJnt("joint1", "joint2", jnts, "y", jointRad, names)

jntSegTest()

Anyone know whats up with this code? I've searched for a long time, and all the indentation errors i found involved mixing tabs with spaces, or not indenting properly after semicolons (definitions, classes, for loops, etc.). So i'm at a loss.

Heres the code for the module neoARLLF if it helps. I presume this code has quite a few errors in it but I cant test out the code to fix it until i can get the import statement to work in the previous module

# Filename: neoARLLF.py
# Created By: Gregory Smith
# Last Edited: 8/20/14
# Description: Neo Auto Rig - Low Level Functions
# Purpose: The classes in this script house all of the low level functions that will be carried out in
# external scripts.

import maya.cmds as mc
import neoARnameConv
from pymel.core import dt

nameC = neoARnameConv.NameConv()

class LowLvlFunc:

    def __init__(self):


    def reverseList(self, givenList):
        """Reverses the given list (eg. [1, 2, 3] would turn into [3, 2, 1]

        Keyword Args
        givenList - list that you want reversed
        """

        newList = givenList[:: - 1]
        return newList


    def copyTranslate(self, source, target):
        """Copies the world-space translate values from one object to another

        Keyword Args
        source - object you want values copied from
        target - object you want values copied to
        """

        translate = mc.xform(source, q=True, ws=True, t=True)
        rotPiv = mc.xform(target, q=True, rp=True)
        newVec = [sum(i) for i in zip(translate, rotPiv)]

        mc.xform(target, a=True, ws=True, t=(newVec[0], newVec[1], newVec[2]))

    def copyRotate(self, source, target):
        """Copies the world-space rotate values from one object to another

        Keyword Args
        source - object you want values copied from
        target - object you want values copied to
        """
        rotate = mc.xform(source, q=True, ws=True, ro=True)

        mc.xform(target, ws=True, ro=(rotate[0], rotate[1], rotate[2]))

    def lockProtectedAttrs (self, control, lock):
        """Locks or unlocks all attributes in custom attributes text file

        Keyword Arguments
        control -- the control you want the attributes locked/unlocked on
        lock -- if you want the control unlocked or locked (0 or 1)
        """

        filePath = (mc.internalVar(usd=True)+"neo_ikFkSnapAttrs")
        attrFile = open(filePath, "r")
        nextLine = f.readLines()
        attrList = []
        while (len(nextLine)>0):
            cleanLine = line.strip(nextLine)
            attrList[len(attrList)] = cleanLine
            print cleanLine
            nextLine = f.readlines()
        f.close()

        def unlock:
            for curAttr in attrList:
                if mc.attributeExists(control, curAttr):
                    mc.setAttr((control+"."+curAttr), lock=False)
        def lock:
            for curAttr in attrArray:
                if mc.attributeExists(control, curAttr):
                    mc.setAttr((control+"."+curAttr), lock=True)

        lockOpt = {
                0 : unlock,
                1 : lock
        }

        lockOpt[lock]()

    def zeroOutCustomAttr(self, control):
        """Zeroes out all user defined, custom attributes on given control

        Keyword Arguments
        control -- control you want attributes zeroed out on
        """
        lockProtectedAttrs(control,1)
        customAttrs = [mc.listAttr(control, ud=True, k=True, u=True)]
        lockProtectedAttrs(control, 0)
        for curAttr in customAttrs:
            mc.setAttr((control+"."+curAttr), 0)
            print ("Resettings attribute "+curAttr)
        print ("Custom Attributes on "+control+" have been zeroed out")

class MidLvlFunc:

    def __init__(self):


    def segmentJnt(self, startJnt, endJnt, jointNum, primAxis, radius, name):

        """Creates 3 evenly spaced joints between 2 given joints

        Keyword Args
        startJnt - first joint, (ex, knee or elbow joint)
        endJnt - second joint, (ex. ankle or wrist joint)
        jointNum - number of segments in the chain
        primAxis - primary axis of joint chain
        radius - radius of other joints
        name - name of auxillary joints
        """

        startVec = mc.xform(q=True, ws=True, t=True, endJnt)
        endVec = mc.xform(q=True, ws=True, t=True, startJnt)
        startAux = mc.joint(n=name[0], p=(dt.Vector(startVec))
        endAux = mc.joint(n=name[(len(name)-1)], p=(dt.Vector(endVec))
        returnList = [startAux]

        for i in xrange(1, jointNum, 1):
            jointAux = mc.joint(n=name[i], o=(0, 0, 0), rad=radius)
            if primAxis = "x":
                mc.move(((endJnt.tx) / jointNum), 0, 0, joint, r=True, ls=True)
            elif primAxis = "y":
                mc.Move(0, ((endJnt.ty) / jointNum), 0, joint, r=True, ls=True)
            else
                mc.Move=(0, 0, ((endJnt.tz) / jointNum), joint, r=True, ls=True)
            returnList.append(jointAux)

        returnList.append(endAux)

        return returnList

Solution

  • The problem is in your class __init__:

    def __init__(self):
    

    You have no code below there, so it errors on the next line. To stub out the function, add a pass statement, like this:

    def __init__(self):
        pass