[maya] カスタム アトリビュート を python で作る場合。

cmds.addAttr(longName=’lastDirPath’,dataType=’string’ )

import maya.cmds as cmds

cmds.select("any")
#custom-attribute-add-python
cmds.addAttr(longName='lastDirPath',dataType='string' )

これをこう使うわけだ

def select_exportDir(self):
    
    filePath = cmds.fileDialog2( cap = '書き出しディレクトリの選択', okc = '書き出しディレクトリを設定',ds = 2, fm = 3,startingDirectory=get_lastExportDirPath())
    if filePath == None:
        return False
    else:
        set_lastExportDirPath(filePath[0]+"/")



def get_lastExportDirPath_ExistBool():
    lastExportDirPath_ExistBool=False
    Attlist=cmds.listAttr( r=True )
    print("Attlist= "+str(Attlist))
    for AttName in Attlist:
        #print("AttName= "+AttName)
        if(AttName=="lastExportDirPath"):
            lastExportDirPath_ExistBool=True
            print("HIT!!!!!!!lastExportDirPath")
    return lastExportDirPath_ExistBool

def addAttr_lastExportDirPath():
    lastExportDirPath_ExistBool= get_lastExportDirPath_ExistBool()
    if(lastExportDirPath_ExistBool==False):
        cmds.addAttr(longName='lastExportDirPath',dataType='string')
        

def set_lastExportDirPath(lastExportDirPath):
    
    selectList=cmds.ls(sl=True)
    if(str(selectList)== "[]"):
        print("なにも選択されていません。0 set_lastExportDirPath")
    else:

        for i in selectList:
            cmds.select(i)
            #---------------------------
            addAttr_lastExportDirPath()
            #---------------------------
            print("i= "+str(i))
            attName=i+"."+'lastExportDirPath'
            print("attName= "+attName)
            cmds.setAttr( attName, lastExportDirPath,type="string")
    cmds.textField("pathTxtFld", edit=True, text=lastExportDirPath)
    cmds.select(selectList)



def get_lastExportDirPath():

    selectList=cmds.ls(sl=True)
    
    lastExportDirPath=""
    if(str(selectList)== "[]"):
        print("なにも選択されていません。3 get_lastExportDirPath")
        lastExportDirPath = get_scenePath()
    else:
        for i in selectList:
            cmds.select(i)
            #---------------------------
            addAttr_lastExportDirPath()
            #---------------------------
            print("i= "+str(i))
            attName=i+"."+'lastExportDirPath'
            print("attName= "+attName)
            lastExportDirPath = cmds.getAttr(attName)
            print("lastExportDirPath="+str(lastExportDirPath))
            if(str(lastExportDirPath)=="None"):
                lastExportDirPath = get_scenePath()
        cmds.select(selectList)
    return lastExportDirPath