Hi,
Can I edit the data type of a attribute . if yes then How ??
Here is how I would do it, examples in Mel, Python and PyMel :). Tested with Maya 2011 Hotfix 3.
You would want to make yourself a function for this ofc so it can handle any type of attribute types / data types and if wanted even type conversion like int –> string so it stores the value and reapplies it to the new attribute. Anyhow this should get you started ![]()
List of attributes maya supports: Attribute and Data types[B]
MEL EXAMPLE[/B]
//Create empty transform node
string $object = `createNode transform -n "testObejct"`;
string $attrLongName0 = "attr0";
string $attrLongName1 = "attr1";
//Add attr0 as double and attr1 as string
addAttr -ln $attrLongName0 -at double;
addAttr -ln $attrLongName1 -dt "string";
//Delete old attribute, make attr0 string instead of double
if (`attributeExists $attrLongName0 $object`)
{
deleteAttr ($object + "." + $attrLongName0);
addAttr -ln $attrLongName0 -dt "string";
}
//Delete old attribute, make attr1 double instead of string
if (`attributeExists $attrLongName1 $object`)
{
deleteAttr ($object + "." + $attrLongName1);
addAttr -ln $attrLongName1 -at double;
}
PYTHON EXAMPLE
import maya.cmds as cmds
object = cmds.createNode("transform", name = "testObject")
attrLongName0 = "attr0"
attrLongName1 = "attr1"
cmds.addAttr(ln = attrLongName0, attributeType = "double")
cmds.addAttr(ln = attrLongName1, dataType = "string")
if cmds.attributeQuery(attrLongName0, node=object, ex=True) is True:
cmds.deleteAttr(object + "." + attrLongName0)
cmds.addAttr(ln = attrLongName0, dataType = "string")
if cmds.attributeQuery(attrLongName1, node=object, ex=True) is True:
cmds.deleteAttr(object + "." + attrLongName1)
cmds.addAttr(ln = attrLongName1, attributeType = "double")
PYMEL EXAMPLE
import pymel.core as pm
object = pm.nt.Transform(n="testObject")
attrLongName0 = "attr0"
attrLongName1 = "attr1"
object.addAttr(attrLongName0, dataType ='string')
object.addAttr(attrLongName1, attributeType ='double')
if object.hasAttr(attrLongName0) is True:
object.deleteAttr(attrLongName0)
object.addAttr(attrLongName0, attributeType='double')
if object.hasAttr(attrLongName1) is True:
object.deleteAttr(attrLongName1)
object.addAttr(attrLongName1, dataType='string')
hey thanks @LoneWolf …