How to add ComponentTags to a mesh

I am trying to create a script that would create a set of ComponentTags to a Mesh. Unfortunately, it’s very hard to find tutorials and examples that do this. Does anyone have any idea how I would proceed? I would imagine I would need to use Maya API and MFnGeometryData, but that’s about the only thing I can think of.

When I make a cube in maya, it auto-creates tags for the 6 faces… So I just saved out a .ma file and took a look. This is the stuff that seemed relevant

createNode mesh -n "pCubeShape1" -p "pCube1";
	setAttr -s 6 ".gtag";
	setAttr ".gtag[0].gtagnm" -type "string" "back";
	setAttr ".gtag[0].gtagcmp" -type "componentList" 1 "f[2]";
	setAttr ".gtag[1].gtagnm" -type "string" "bottom";
	setAttr ".gtag[1].gtagcmp" -type "componentList" 1 "f[3]";
	setAttr ".gtag[2].gtagnm" -type "string" "front";
	setAttr ".gtag[2].gtagcmp" -type "componentList" 1 "f[0]";
	setAttr ".gtag[3].gtagnm" -type "string" "left";
	setAttr ".gtag[3].gtagcmp" -type "componentList" 1 "f[5]";
	setAttr ".gtag[4].gtagnm" -type "string" "right";
	setAttr ".gtag[4].gtagcmp" -type "componentList" 1 "f[4]";
	setAttr ".gtag[5].gtagnm" -type "string" "top";
	setAttr ".gtag[5].gtagcmp" -type "componentList" 1 "f[1]";

So I guessed that this would work

cmds.setAttr('pCubeShape1.componentTags[6].componentTagName', "test", type="string")
cmds.setAttr('pCubeShape1.componentTags[6].componentTagContents', 2, "f[2]", "f[4]", type="componentList")

And it did

[edit] Updated to use the full attribute names because you should always use full names

1 Like