import maya.cmds as cmds cmds.file(new=1,f=1) sphere_xform, sphere_shape = cmds.polySphere(n='Earth') cmds.addAttr(sphere_xform, attributeType = 'float', shortName = 'mass', longName = 'Mass', defaultValue = 5.9742e24) print(cmds.getAttr(sphere_xform+'.mass'))
cmds.addAttr(sphere_xform, dataType= 'string', shortName = 'alt', longName = 'alternateName') cmds.setAttr('%s.alternateName'%sphere_xform, 'Terra', type='string') print (cmds.getAttr('%s.alt'%sphere_xform))
addAttr()添加属性
上面是添加浮点数和添加字符串。添加浮点数时候,设置了默认值。
添加字符串属性时,加dataType标志,在设置字符串时,要指定type。