Skip to content

pymxs Helpful Snippets

Travis Evashkevich edited this page Mar 4, 2020 · 6 revisions

Selection Sets:

Getting Named Selection Sets is a fairly straightforward procedure for Object Selection Sets, but it's a bit more "difficult" to find how to do it for object mode ones (Vert/Edge/Faces etc), so to save the hassle Getting SelSets From object modes (verts/edges/poly/etc) This is the "same" just change whatever mode you're looking for

  • Get Selection Set names from Faces Sets: import pymxs rt = pymxs.runtime thing = rt.getCurrentSelection()[0] print(thing.Faces.selSetNames) #("TestSet", "TestSet2") # example output Obviously then you can select a set by doing something like: thing.selectedFaces = thing.Faces["TestSet2"]

Get All Materials

Does a check to see if you have multi material on your model, if it does, iterates and tries to do a face select to check if the material is actually on the model and returns a list of material ID's and what faces have it.

    materials = []
    dupe = rt.copy(model)
    rt.resetXForm(dupe)
    rt.collapseStack(dupe)
    material = dupe.material
    if rt.classOf(material) == rt.Multimaterial:
        for matID in xrange(material.numsubs):
            #see if we can select any faces for each material
            dupe.selectByMaterial(matID+1)
            faces = dupe.GetSelection(rt.name("Face"))
            numSelected = faces.numberset
            if numSelected > 0:
                materials.append({material[matID]: numSelected})
    elif rt.classOf(material) == rt.StandardMaterial:
        # if we only have one material we assume that it is on every face
        materials.append({material.name: dupe.mesh.numFaces})
    rt.delete(dupe)
    return materials
Clone this wiki locally