Script/ Code Component tag editing in Maya 2022

Script/ Code Component tag editing in Maya 2022

cmwVXDCP
Explorer Explorer
1,886 Views
9 Replies
Message 1 of 10

Script/ Code Component tag editing in Maya 2022

cmwVXDCP
Explorer
Explorer

In Maya 2022, Is it possible without creating a custom node to edit component tags on a mesh or a cluster via

script?  I did manage to find the code to query weights and indices using maya.cmds.geometryAttrInfo.  However, 

unlike using the objectSet support from Maya 2020 and prior, I'm not seeing how to edit component tags

procedurally?  For example, I want to add points, remove points to component tags from Python or C++.  I also

want to be able to query component tags on meshes and deformers.  I also want to set a cluster to use component

tags from script or C++.

0 Likes
1,887 Views
9 Replies
Replies (9)
Message 2 of 10

absoluteKelvin
Collaborator
Collaborator

im looking for this as well. but i have a feeling they havent implement it yet in script

https://www.artstation.com/kelvintam
0 Likes
Message 3 of 10

cmwVXDCP
Explorer
Explorer

It is still possible to edit the cluster weights over the entire mesh using the MFnWeightGeometryFilter.   

0 Likes
Message 4 of 10

absoluteKelvin
Collaborator
Collaborator

copied from a post by Will Telford from another thread. Should cover the component editing and querying as well in python.

 

#Create Mesh
sphere=cmds.polySphere()[0]
sphere = cmds.listRelatives(sphere, shapes=True)[0]

#Create Component Tag
cmds.setAttr(sphere + '.componentTags[0].componentTagName', 'test', type='string')
cmds.setAttr(sphere + '.componentTags[0].componentTagContents', 2,'f[0:99]', 'f[200:299]', type='componentList')



#Query Component Tags
cmds.geometryAttrInfo(sphere + '.outMesh', componentTagNames=True)

# Result: ['test'] # 


#Query a description of the componentTags and the nodes in the chain where they were added to the geometry.
cmds.geometryAttrInfo(sphere + '.outMesh', componentTagHistory=True)

# Result: [{'affectCount': 200,
  'category': 4,
  'editable': True,
  'fullCount': 400,
  'key': 'test',
  'modified': False,
  'node': 'pSphereShape4',
  'procedural': False}] # 


#Get the components that are members of the "test" tag
cmds.geometryAttrInfo(sphere + '.outMesh', components=True, componentTagExpression='test')

# Result: ['f[0:99]', 'f[200:299]'] # 

 

https://www.artstation.com/kelvintam
0 Likes
Message 5 of 10

cmwVXDCP
Explorer
Explorer

Thanks.  This is helpful.  Do you know how it would work for vertices and edges also?  Also, what is the argument 

which says "2" in the setAttr?  What does the two mean?

 

 

Message 6 of 10

cmwVXDCP
Explorer
Explorer

Edge example: "e[0:10]"

Vertex example "vtx[0:3]"

0 Likes
Message 7 of 10

cmwVXDCP
Explorer
Explorer

For a cluster deformer where it has "cluster1Tag" which is what the default component tag is named once

it is converted, it appears if you run the commands, you are no editing the existing component tag, but creating a new one.  Whereas for custom tags created after the fact with different names such as "test" you can reach in and edit the existing tag.

0 Likes
Message 8 of 10

cmwVXDCP
Explorer
Explorer

Also unclear now to reassign a different tag to a cluster deformer once it's tied to cluster1Tag.

0 Likes
Message 9 of 10

absoluteKelvin
Collaborator
Collaborator

2 means two entries f[0:99]', 'f[200:299]'

 

im unfamiliar with the ClusterTag

https://www.artstation.com/kelvintam
0 Likes
Message 10 of 10

mathiasaubry
Explorer
Explorer

It's been a while nobody posted on this question, but since I had to find the way to edit the componentTag content, here is the way I found to be more proper than the setAttr, since it seems that you need a eval if you don't know how many entries you have.

 

here is the way I found to do it:

cmds.componentTag(["geo.vtx[1140:1141],geo.vtx[1150]"], tn='cluster6', m='replace')
and for m (modify) you can use replace, add, remove
and tn being the name of the componentTag